| | |
| | | |
| | | <script> |
| | | import { $ } from '@tarojs/extend'; |
| | | import Taro from '@tarojs/taro'; |
| | | import { AtInput, AtImagePicker, AtCurtain } from 'taro-ui-vue'; |
| | | import { $fetcherCommon } from '@fetchers/FCommon'; |
| | | import './cImagePicker.scss'; |
| | | |
| | | export default { |
| | |
| | | duration: 2000, |
| | | }); |
| | | }, |
| | | $uploadImage(callback) { |
| | | const url = $fetcherCommon.getUploadImgURL(); |
| | | const uploadTeam = []; |
| | | const imgs = []; |
| | | this.files.forEach((file) => { |
| | | if (file.type === 'btn') { |
| | | return; |
| | | } |
| | | // blob 二进制文件才上传 |
| | | if (file.url.indexOf('blob') >= 0) { |
| | | uploadTeam.push( |
| | | new Promise((resolve, reject) => { |
| | | Taro.uploadFile({ |
| | | url, |
| | | filePath: file.url, |
| | | name: 'file', |
| | | formData: {}, |
| | | success(res) { |
| | | const res2 = |
| | | typeof res.data === 'string' ? JSON.parse(res.data) : res.data; |
| | | if (res2.state.code === 2000) { |
| | | resolve($fetcherCommon.transImgPath('fix', res2.data.src)); |
| | | } else { |
| | | reject({ message: 'res2.state.msg' }); |
| | | } |
| | | }, |
| | | cancel() { |
| | | reject({ message: '上传图片已取消!' }); |
| | | }, |
| | | fail() { |
| | | reject({ message: '上传图片失败!' }); |
| | | }, |
| | | }); |
| | | }) |
| | | ); |
| | | } |
| | | // 其他类型视为 url,忽略 |
| | | else { |
| | | uploadTeam.push(Promise.resolve(file.url)); |
| | | } |
| | | }); |
| | | Promise.all(uploadTeam) |
| | | .then((res) => { |
| | | this.itemRes.onChange(res); |
| | | setTimeout(() => { |
| | | callback('success'); |
| | | }, 0); |
| | | }) |
| | | .catch((err) => { |
| | | callback('error', err); |
| | | }); |
| | | }, |
| | | }, |
| | | mounted() { |
| | | $(this.$refs.input.$el).find('.at-input__input').prepend(this.$refs.picker.$el); |