123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- const app = getApp()
- Component({
- properties: {
- list: { type: Array, value: [] },
- name: { type: String },
- count: { type: Number, value: 1 },
- },
- data: {},
- methods: {
- // 图片上传
- imgUpload() {
- const that = this;
- const name = that.data.name;
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success(res) {
- const file = res.tempFilePaths;
- wx.uploadFile({
- url: `${app.globalData.serverUrl}/files/test/upload`,
- filePath: file[0],
- name: 'file',
- formData: {},
- success: (arr) => {
- let aee = JSON.parse(arr.data);
- if (arr.statusCode == 200) {
- that.triggerEvent('imgUpload', { data: { name: aee.name, url: `${app.globalData.serverUrl}` + aee.uri, uri: aee.uri }, name: name })
- } else {
- wx.showToast({ title: `${arr.errMsg}`, icon: 'error', duration: 2000 })
- }
- }
- })
- }
- })
- },
- imgDel(e) {
- const that = this;
- const name = that.data.name;
- const { item, index } = e.currentTarget.dataset;
- that.triggerEvent('imgDel', { data: { file: item, index: index }, name: name })
- },
- // 预览
- toView: function (e) {
- const { item } = e.currentTarget.dataset;
- wx.previewImage({ current: '', urls: [item.url] })
- }
- }
- })
|