Commit 6fa418e4efe2f1da3ee9dc3fe077d3dd925281d1

Authored by liujun001
1 parent d6fa5a51

优化图片上传和显示

src/api/driver/driver.js
@@ -38,7 +38,7 @@ export function addDriver(data) { @@ -38,7 +38,7 @@ export function addDriver(data) {
38 // 修改驾驶员信息 38 // 修改驾驶员信息
39 export function updateDriver(data) { 39 export function updateDriver(data) {
40 return request({ 40 return request({
41 - url: '/driver/driver', 41 + url: '/driver/driver/edit',
42 method: 'put', 42 method: 'put',
43 data: data 43 data: data
44 }) 44 })
src/components/ImageUpload/index.vue
@@ -64,7 +64,7 @@ const number = ref(0); @@ -64,7 +64,7 @@ const number = ref(0);
64 const uploadList = ref([]); 64 const uploadList = ref([]);
65 const dialogImageUrl = ref(""); 65 const dialogImageUrl = ref("");
66 const dialogVisible = ref(false); 66 const dialogVisible = ref(false);
67 -const baseUrl = import.meta.env.VITE_APP_BASE_API; 67 +const baseUrl = "";
68 const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + props.uploadUrlSuffix); // 上传的图片服务器地址 68 const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + props.uploadUrlSuffix); // 上传的图片服务器地址
69 const headers = ref({ Authorization: "Bearer " + getToken() }); 69 const headers = ref({ Authorization: "Bearer " + getToken() });
70 const fileList = ref([]); 70 const fileList = ref([]);
@@ -73,17 +73,17 @@ const showTip = computed( @@ -73,17 +73,17 @@ const showTip = computed(
73 ); 73 );
74 74
75 watch(() => props.modelValue, val => { 75 watch(() => props.modelValue, val => {
  76 + console.log("value=========>"+val);
  77 +
76 if (val) { 78 if (val) {
77 // 首先将值转为数组 79 // 首先将值转为数组
78 const list = Array.isArray(val) ? val : props.modelValue.split(","); 80 const list = Array.isArray(val) ? val : props.modelValue.split(",");
79 // 然后将数组转为对象数组 81 // 然后将数组转为对象数组
80 fileList.value = list.map(item => { 82 fileList.value = list.map(item => {
  83 + console.log("111111111111111111111111");
  84 +
81 if (typeof item === "string") { 85 if (typeof item === "string") {
82 - if (item.indexOf(baseUrl) === -1) {  
83 - item = { name: baseUrl + item, url: baseUrl + item };  
84 - } else {  
85 - item = { name: item, url: item };  
86 - } 86 + item = { name: item, url: item };
87 } 87 }
88 return item; 88 return item;
89 }); 89 });
@@ -174,6 +174,9 @@ function handleUploadError() { @@ -174,6 +174,9 @@ function handleUploadError() {
174 174
175 // 预览 175 // 预览
176 function handlePictureCardPreview(file) { 176 function handlePictureCardPreview(file) {
  177 + console.log("file.url:"+file.url);
  178 + console.log(file);
  179 +
177 dialogImageUrl.value = file.url; 180 dialogImageUrl.value = file.url;
178 dialogVisible.value = true; 181 dialogVisible.value = true;
179 } 182 }
src/utils/request.js
@@ -17,7 +17,7 @@ const service = axios.create({ @@ -17,7 +17,7 @@ const service = axios.create({
17 // axios中请求配置有baseURL选项,表示请求URL公共部分 17 // axios中请求配置有baseURL选项,表示请求URL公共部分
18 baseURL: import.meta.env.VITE_APP_BASE_API, 18 baseURL: import.meta.env.VITE_APP_BASE_API,
19 // 超时 19 // 超时
20 - timeout: 10000 20 + timeout: 90000
21 }) 21 })
22 22
23 // request拦截器 23 // request拦截器
src/views/driver/driver/index.vue
@@ -248,6 +248,7 @@ function handleUpdate(row) { @@ -248,6 +248,7 @@ function handleUpdate(row) {
248 form.value = response.data; 248 form.value = response.data;
249 open.value = true; 249 open.value = true;
250 title.value = "修改驾驶员信息"; 250 title.value = "修改驾驶员信息";
  251 +
251 }); 252 });
252 } 253 }
253 254