123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- const reqInterface = require("../../../api/models");
- const Base64 = require("../../../utils/base64");
- const {
- imagePrefix, getApi
- } = require("../../../utils/dataHelper");
-
- Component({
-
- /**
- * 组件的属性列表
- */
- properties: {
- image: {
- type: String,
- value: ''
- },
- uploadTxt: String,
- },
-
- observers: {
- 'image': function (val) {
- let self = this;
- if (val) {
- self.setData({
- imageUrl: val
- })
- }
- }
- },
-
- 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: '',
- imageUrl: '',
- header: {
- 'Authorization': `Basic ${Base64.Base64.encode('miniapp:miniapp_secret')}`,
- 'Blade-Auth': `bearer ${wx.getStorageSync('token')}`
- }
- },
-
- /**
- * 组件的方法列表
- */
- methods: {
- uploadSuccess(e) {
- let self = this;
- let res = JSON.parse(e.detail.file.res.data);
- if (res.data) {
- self.setData({
- image: res.data.url
- })
- } else {
- if (res.code == 401) {
- wx.showModal({
- title: '错误信息',
- content: '登录已过期',
- confirmText: '重新登录',
- showCancel: false,
- success(res1) {
- wx.removeStorageSync('token')
- wx.reLaunch({
- url: '/pages/my/index/index',
- })
- }
- })
- } else {
- wx.showModal({
- title: '错误信息',
- content: '上传报错,请联系相关人员',
- confirmText: '知道了',
- showCancel: false,
- success(res1) {
-
- }
- })
- }
- }
- self.triggerEvent('sumbitImageInfo', res.data)
- },
-
-
- uploadFail(e) {
- console.log(e)
- },
- preview(e) {
- wx.previewImage({
- current: e.currentTarget.dataset.src, // 当前显示图片的http链接
- urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表
- })
- },
- }
- })
|