guhongwei il y a 3 ans
Parent
commit
2d02ff9da1

+ 56 - 0
commpents/upload/index.js

@@ -0,0 +1,56 @@
+// commpents/mobile-frame/mobile-main.js
+const app = getApp()
+Component({
+  /**
+   * 组件的属性列表
+   */
+  options: { multipleSlots: true },
+  properties: {
+    list: { type: 'array', value: [] },
+    count: { type: Number, value: 1 }
+  },
+
+  // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
+  attached: function () { }, // 此处attached的声明会被lifetimes字段中的声明覆盖
+  ready: function () { },
+  pageLifetimes: {
+    // 组件所在页面的生命周期函数
+    show: function () { },
+    hide: function () { },
+    resize: function () { },
+  },
+  /**
+   * 组件的初始数据
+   */
+  data: {
+
+  },
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    // 图片上传
+    imgUpload(event) {
+      const { file } = event.detail;
+      wx.uploadFile({
+        url: `${app.globalData.imageUrl}/files/court/elimg/upload`,
+        filePath: file.url,
+        name: 'file',
+        formData: {},
+        success: (res) => {
+          let arr = JSON.parse(res.data);
+          if (res.statusCode == 200) {
+            this.triggerEvent('imgUpload', { name: arr.name, url: `${app.globalData.imageUrl}` + arr.uri, uri: arr.uri })
+          } else {
+            wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 })
+          }
+        }
+      })
+    },
+    // 图片删除
+    imgDel(e) {
+      this.triggerEvent('imgDel', { file: e.detail.file, index: e.detail.index })
+    }
+  }
+})
+

+ 4 - 0
commpents/upload/index.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 1 - 0
commpents/upload/index.wxml

@@ -0,0 +1 @@
+<van-uploader file-list="{{list}}" max-count="{{count}}" bind:after-read="imgUpload" bind:delete="imgDel" />

+ 1 - 0
commpents/upload/index.wxss

@@ -0,0 +1 @@
+/* commpents/upload/index.wxss */

+ 13 - 0
commpents/upload/read.md

@@ -0,0 +1,13 @@
+# 上传图片组件使用说明
+## 参数
+### 图片存储列表:list
+### 图片上传数量限制:count
+
+## 方法
+### 上传图片---imgUpload
+### 传回父组件参数,图片名称:name,图片完整地址:url,图片地址:uri
+### 父组价接收参数变量:e.detail
+
+### 删除图片---imgDel
+### 传回父组件参数:图片数据:file,图片所在列表下标:index
+### 父组件接收参数变量:e.detail

BIN
image/bisai.png


BIN
image/chuangjian.png


BIN
image/home.png


BIN
image/tou.png