You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.0 KiB

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