123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // commpents/mobile-frame/mobile-main.js
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- options: { multipleSlots: true },
- properties: {
- list: { type: Array, value: [] },
- count: { type: Number, value: 1 },
- previewSize: { type: String, value: '30' }
- },
- // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
- attached: function () { }, // 此处attached的声明会被lifetimes字段中的声明覆盖
- ready: function () { },
- pageLifetimes: {
- // 组件所在页面的生命周期函数
- show: function () { },
- hide: function () { },
- resize: function () { },
- },
- /**
- * 组件的初始数据
- */
- data: {
- },
- /**
- * 组件的方法列表
- */
- methods: {
- // 图片上传
- imgUpload: function () {
- const that = this;
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success(res) {
- const file = res.tempFilePaths;
- wx.uploadFile({
- url: `${app.globalData.fileUrl}/files/court/elimg/upload`,
- filePath: file[0],
- name: 'file',
- formData: {},
- success: (arr) => {
- let aee = JSON.parse(arr.data);
- if (arr.statusCode == 200) {
- that.triggerEvent('imgUpload', { name: aee.name, url: `${app.globalData.fileUrl}` + aee.uri, uri: aee.uri })
- } else {
- wx.showToast({ title: `${arr.errMsg}`, icon: 'error', duration: 2000 })
- }
- }
- })
- }
- })
- },
- // 图片删除
- imgDel: function (e) {
- const that = this;
- const { item, index } = e.currentTarget.dataset;
- that.triggerEvent('imgDel', { file: item, index: index })
- },
- // 预览
- toView: function (e) {
- const { item } = e.currentTarget.dataset;
- wx.previewImage({
- current: '',
- urls: [item.url]
- })
- }
- }
- })
|