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.
134 lines
3.0 KiB
134 lines
3.0 KiB
// pages/topics/common/message/index.js
|
|
import { config } from '../../../config.js'
|
|
import { store } from '../../../utils/store.js'
|
|
import { TopicModel } from '../../../models/topic.js'
|
|
let topicModel = new TopicModel()
|
|
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
messageTitle:"",
|
|
messageDetail:"",
|
|
files: [],
|
|
},
|
|
// lifetimes: {
|
|
// attached: function () {
|
|
// // 在组件实例进入页面节点树时执行
|
|
// },
|
|
// detached: function () {
|
|
// // 在组件实例被从页面节点树移除时执行
|
|
// }
|
|
// },
|
|
// attached: function () {
|
|
// console.log('啦啦啦')
|
|
// },
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
attached: function () {
|
|
console.log('啦啦啦')
|
|
this.setData({
|
|
uplaodFile: this.uplaodFile.bind(this)
|
|
})
|
|
|
|
|
|
|
|
},
|
|
methods: {
|
|
bindTextInput(e) {
|
|
this.setData({
|
|
messageTitle: e.detail.value
|
|
})
|
|
},
|
|
bindTextAreaInput(e) {
|
|
this.setData({
|
|
messageDetail: e.detail.value
|
|
})
|
|
},
|
|
|
|
uplaodFile(files) {
|
|
console.log('upload files', files)
|
|
// 文件上传的函数,返回一个promise
|
|
const token = store.readToken()
|
|
console.log(token)
|
|
return new Promise((resolve, reject) => {
|
|
files.tempFilePaths.forEach(item => {
|
|
wx.uploadFile({
|
|
url: config.api_url + "/api/common/upload",
|
|
filePath: item,
|
|
header: {
|
|
'token': token,
|
|
'content-type': 'application/json',
|
|
},
|
|
name: 'files',
|
|
success: (res) => {
|
|
console.log(res);
|
|
const data = JSON.parse(res.data)
|
|
const image = {
|
|
url: config.api_url + '/' + data.result.imgUrl,
|
|
}
|
|
this.setData({
|
|
files: [...this.data.files, image]
|
|
})
|
|
resolve(this.data.files)
|
|
}
|
|
})
|
|
})
|
|
})
|
|
},
|
|
deleteFile(e) {
|
|
console.log(e)
|
|
let tempImages = this.data.files
|
|
const index = e.detail.index
|
|
|
|
tempImages.splice(index, 1);
|
|
this.setData({
|
|
files: tempImages
|
|
})
|
|
},
|
|
|
|
submit() {
|
|
if (this.data.messageTitle === '') {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请输入标题',
|
|
showCancel: false
|
|
})
|
|
return
|
|
}
|
|
if (this.data.messageDetail === ''){
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请输入正文内容',
|
|
showCancel:false
|
|
})
|
|
return
|
|
}
|
|
|
|
topicModel.addMessage(this.data.messageTitle, this.data.messageDetail,this.data.files,res=>{
|
|
if(res.code === 200){
|
|
this.setData({
|
|
messageTitle:'',
|
|
messageDetail: '',
|
|
files:[],
|
|
},()=>{
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|