// pages/quest/subpage/detail/components/link/link.js import { http } from '../../../../../../utils/util' Component({ /** * 组件的属性列表 */ properties: { data: { type: Object, value: {} }, linkre: { type: Array, value: {} } }, /** * 组件的初始数据 */ data: { platforms: [{ id: 1, name: '抖音' }, { id: 2, name: '快手' }, { id: 3, name: '朋友圈' }, { id: 4, name: '视频号' } ], platform: null, platformdia: false, link: '', cdn: getApp().globalData.cdn, link_type: false, image: null, upload: getApp().globalData.upload, }, /** * 组件的方法列表 */ methods: { plachoose(e) { this.setData({ platformdia: true }) }, plachoose2(e) { console.log(e.currentTarget.dataset.mes) if (e.currentTarget.dataset.mes.id === 3 || e.currentTarget.dataset.mes.id === 4) { this.setData({ link_type: true }) } else { this.setData({ link_type: false }) } this.setData({ platform: e.currentTarget.dataset.mes, platformdia: false }) }, linkin(e) { // console.log(e.detail.value) this.setData({ link: e.detail.value }) }, up(e) { if (!this.data.platform) { wx.showToast({ title: '请选择平台', icon: 'none', duration: 2000 }) } else if (this.data.platform.id === 1 || this.data.platform.id === 2) { if (!this.data.link) { wx.showToast({ title: '请输入链接', icon: 'none', duration: 2000 }) } else if (this.data.link.indexOf('http') === -1) { wx.showToast({ title: '请输入正确的链接', icon: 'none', duration: 2000 }) } else { http("/video/userAdd", "post", { id: this.data.data.id, type: this.data.platform.id, url: this.data.link }).then(res => { wx.showToast({ title: res.data, icon: 'none', duration: 3000 }).then(res => { this.triggerEvent('getdata', '') this.setData({ link_type: false, platform: null, link: '' }) }) }) } } else if (this.data.platform.id === 3 || this.data.platform.id === 4) { if (!this.data.image) { wx.showToast({ title: '请上传图片', icon: 'none', duration: 2000 }) } else { http("/video/userAdd", "post", { id: this.data.data.id, type: this.data.platform.id, url: this.data.cdn + this.data.image }).then(res => { wx.showToast({ title: res.data, icon: 'none', duration: 3000 }).then(res => { this.triggerEvent('getdata', '') this.setData({ link_type: false, platform: null, link: '' }) }) }) } } }, chooseImage() { let that = this wx.chooseMedia({ count: 1, success(res) { const tempFiles = res.tempFiles console.log('chooseImage',res) wx.uploadFile({ url: that.data.upload + '/util/upload', filePath: tempFiles[0].tempFilePath, name: 'file', formData: { }, success(res) { console.log('uploadFile',res) console.log(JSON.parse(res.data)) that.setData({ image: JSON.parse(res.data).data.fileUrl }) // do something } }) } }) } } })