123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- const reqInterface = require("../../../api/models");
- const Base64 = require("../../../utils/base64");
- const {
- imagePrefix, getApi
- } = require("../../../utils/dataHelper");
- Component({
-
- /**
- * 组件的属性列表
- */
- properties: {
- images: {
- type: Array,
- value: []
- },
- imagesPath: {
- type: String,
- value: ''
- },
- uploadTxt: String,
- },
-
- observers: {
- 'images': function (val) {
- let self = this;
- if (val) {
- self.setData({
- imageList: val
- })
- }
- },
- 'imagesPath': function (val) {
- let self = this;
- if (val) {
- self.data.imagePathList = val.split(",")
- self.setData({
- imagePathList: self.data.imagePathList
- })
- }
- },
-
- },
-
- lifetimes: {
- attached() {
- this.setData({
- 'header.Blade-Auth': `bearer ${wx.getStorageSync('token')}`
- })
- this.setData({
- api: getApi()
- })
- }
- },
-
- data: {
- styleCss: 'padding: 20rpx 0; line-height: 36rpx font-size: 28rpx; border-bottom: 1rpx dashed #f0f0f0;',
- api: '',
- imageList: [],
- imagePathList: [],
- tempImageFiles: [],
- header: {
- 'Authorization': `Basic ${Base64.Base64.encode('miniapp:miniapp_secret')}`,
- 'Blade-Auth': `bearer ${wx.getStorageSync('token')}`
- }
- },
-
- /**
- * 组件的方法列表
- */
- methods: {
- uploadFiles(e) {
- let self = this;
- wx.showActionSheet({
- itemList: ['从相册中选择', '拍照'],
- success(res) {
- if (res.tapIndex == 0) {
- self.chooseWxImage('album');
- } else if (res.tapIndex == 1) {
- self.chooseWxImage('camera');
- }
- },
- fail(res) {
- console.log(res.errMsg)
- }
- })
- },
-
- chooseWxImage(type) {
- let self = this;
- wx.chooseMedia({
- mediaType: "image",
- sizeType: ['original', 'compressed'],
- sourceType: [type],
- async success(res) {
- self.setData({
- tempImageFiles: res.tempFiles
- })
- for (let i = 0; i < self.data.tempImageFiles.length; i++) {
- let res = await reqInterface.PostImageUpload(self.data.tempImageFiles[i].tempFilePath);
- self.data.imageList.push(res.data.url)
- self.data.imagePathList.push(res.data.path)
- }
- self.setData({
- imageList: self.data.imageList,
- imagePathList: self.data.imagePathList
- })
- self.triggerEvent('sumbitImageInfo', {
- images: self.data.imageList,
- imagesPath: self.data.imagePathList
- })
- }
- })
- },
-
- delImage(e) {
- let self = this;
- self.data.imageList.splice(e.currentTarget.dataset.index, 1)
- self.data.imagePathList.splice(e.currentTarget.dataset.index, 1)
- self.setData({
- imageList: self.data.imageList,
- imagePathList: self.data.imagePathList
- })
- self.triggerEvent('sumbitImageInfo', {
- images: self.data.imageList,
- imagesPath: self.data.imagePathList
- })
-
- },
-
- imgPreview(e) {
- let self = this;
- wx.previewImage({
- urls: [e.currentTarget.dataset.href]
- })
- },
- }
- })
|