234 lines
4.8 KiB
JavaScript
234 lines
4.8 KiB
JavaScript
// pages/article/publish2.js
|
|
import request from '../../utils/request'
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
categoryList: [],
|
|
currentTab: 0,
|
|
layerHide: false,
|
|
typeName: '',
|
|
countPic: 1, //上传图片最大数量
|
|
showImgUrl: "https://test-firefly-media.oss-cn-shenzhen.aliyuncs.com", //路径拼接,一般上传返回的都是文件名,
|
|
uploadImgUrl: 'https://api.fireflysg.com/firefly/media-room/file/upload', //图片的上传的路径
|
|
switch: false,
|
|
content: '',
|
|
title: '',
|
|
point: '',
|
|
categoryId: 1,
|
|
videoUrl: '',
|
|
newVideoUrl: ''
|
|
},
|
|
bindlongpressimg() {
|
|
this.setData({
|
|
videoUrl: '',
|
|
newVideoUrl: ''
|
|
})
|
|
},
|
|
submit() {
|
|
let datas = {
|
|
categoryId: this.data.categoryId,
|
|
title: this.data.title,
|
|
intro: this.data.content,
|
|
conver: this.data.conver,
|
|
videoUrl: this.data.newVideoUrl,
|
|
display: 1
|
|
}
|
|
console.log(datas)
|
|
request._post('/firefly/video/add/new', datas,
|
|
res => {
|
|
if (res.retCode == 0) {
|
|
wx.hideLoading();
|
|
setTimeout(() => {
|
|
wx.showToast({
|
|
title: '发布成功',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
}, 100);
|
|
wx.switchTab({
|
|
url: '/pages/home/home',
|
|
})
|
|
}
|
|
}
|
|
)
|
|
},
|
|
currentTab: function (e) {
|
|
var categoryItem = e.currentTarget.dataset.item
|
|
if (this.data.categoryId == categoryItem.id) {
|
|
return;
|
|
}
|
|
this.setData({
|
|
categoryId: categoryItem.id,
|
|
typeName: categoryItem.name,
|
|
layerHide: false
|
|
})
|
|
},
|
|
getInputTitle(e) {
|
|
this.setData({
|
|
title: e.detail.value
|
|
})
|
|
},
|
|
getInputAddress(e) {
|
|
this.setData({
|
|
address: e.detail.value
|
|
})
|
|
},
|
|
getInputContent(e) {
|
|
this.setData({
|
|
content: e.detail.value
|
|
})
|
|
},
|
|
getInputPoint(e) {
|
|
this.setData({
|
|
point: e.detail.value
|
|
})
|
|
},
|
|
uploadVideo() {
|
|
var _this = this
|
|
wx.chooseMedia({
|
|
mediaType: ['video'],
|
|
sourceType: ['album', 'camera'],
|
|
sizeType: ['compressed'],
|
|
maxDuration: 15,
|
|
camera: 'back',
|
|
// compressed:true,
|
|
success(res) {
|
|
console.log(res)
|
|
_this.setData({
|
|
videoUrl: res.tempFiles[0].tempFilePath
|
|
})
|
|
_this.uploadFileVideo(res.tempFiles[0].tempFilePath)
|
|
// wx.compressVideo(
|
|
// {
|
|
// src: res.tempFiles[0].tempFilePath,
|
|
// quality: 'low',
|
|
// success(re) {
|
|
// console.log(re)
|
|
// _this.uploadFileVideo(re.tempFilePath)
|
|
// },
|
|
// fail(err) {
|
|
// console.log(err)
|
|
// },
|
|
// complete() {
|
|
// console.log('ssssss')
|
|
// }
|
|
// }
|
|
// )
|
|
},
|
|
fail(res) {
|
|
console.log('失败');
|
|
}
|
|
})
|
|
},
|
|
uploadFileVideo(url) {
|
|
console.log(url)
|
|
wx.showLoading({
|
|
title: '上传中...',
|
|
mask: true,
|
|
})
|
|
var _this = this
|
|
wx.uploadFile({
|
|
url: this.data.uploadImgUrl,
|
|
filePath: url,
|
|
header: {
|
|
'content-type': 'multipart/form-data',
|
|
'terminal': 'MINI-PROGRAM',
|
|
'token': wx.getStorageSync("token") || '',
|
|
},
|
|
timeout: 30000,
|
|
name: 'file',
|
|
formData: null,
|
|
success(res) {
|
|
wx.hideLoading()
|
|
var videoData = res.data
|
|
videoData = JSON.parse(videoData);
|
|
if (videoData.retCode == 0) {
|
|
_this.setData({
|
|
newVideoUrl: videoData.body.mediaURL
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
myEventListener1: function (e) {
|
|
console.log("上传的图片结果集合")
|
|
console.log(e.detail.picsList)
|
|
this.setData({
|
|
conver: e.detail.picsList[0].mediaURL
|
|
})
|
|
},
|
|
typeEvent() {
|
|
this.setData({
|
|
layerHide: true
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.getcategory()
|
|
},
|
|
getcategory() {
|
|
request._post('/firefly/category/list', {
|
|
type: 1
|
|
},
|
|
res => {
|
|
if (res.retCode == 0) {
|
|
this.setData({
|
|
categoryList: res.body
|
|
})
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |