| | |
| | | type: Number, |
| | | default: 1, |
| | | }, |
| | | // 上传图片参数 |
| | | params: { |
| | | type: Object, |
| | | default: () => {}, |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | file.fileName = this.fileNames[file.url]; |
| | | files.push(file); |
| | | }); |
| | | uploadImage(files, (state, res) => { |
| | | if (state === 'success') { |
| | | this.itemRes.onChange(res); |
| | | setTimeout(() => { |
| | | callback(state); |
| | | }, 10); |
| | | } else if (state === 'error') { |
| | | callback(state, res); |
| | | } |
| | | }); |
| | | uploadImage( |
| | | files, |
| | | (state, res) => { |
| | | if (state === 'success') { |
| | | this.itemRes.onChange(res); |
| | | setTimeout(() => { |
| | | callback(state); |
| | | }, 10); |
| | | } else if (state === 'error') { |
| | | callback(state, res); |
| | | } |
| | | }, |
| | | this.params |
| | | ); |
| | | }, |
| | | }, |
| | | mounted() { |
| | |
| | | // 图片上传节流 |
| | | const _readyUpload = {}; |
| | | |
| | | export const uploadImage = (files, callback) => { |
| | | export const uploadImage = (files, callback, params) => { |
| | | if (!files || files.length === 0) { |
| | | callback('success', []); |
| | | return; |
| | |
| | | ...requestFile, |
| | | header, |
| | | name: 'file', |
| | | formData: {}, |
| | | formData: { ...params }, |
| | | timeout: 30 * 1000, |
| | | success(res) { |
| | | const res2 = |
| | | typeof res.data === 'string' |
| | | ? JSON.parse(res.data) |
| | | : res.data; |
| | | let res2; |
| | | try { |
| | | res2 = |
| | | typeof res.data === 'string' |
| | | ? JSON.parse(res.data) |
| | | : res.data; |
| | | } catch (err) { |
| | | reject({ |
| | | ...requestFile, |
| | | response: res, |
| | | message: '上传图片异常!', |
| | | }); |
| | | return; |
| | | } |
| | | // 上传成功 |
| | | if (res2.state.code === 2000) { |
| | | const imgUrl = $fetchCommon.transImgPath( |