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.

141 lines
3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// sumbit.ts
// pages/list/list.js
Page({
/**
* 页面的初始数据
*/
data: {
id:"",
name: "",
property:""
},
onUpload(){
let that=this
let skey=wx.getStorageSync('skey')
wx.chooseMessageFile({
count:1,
success(res) {
const tempFilePaths = res.tempFiles;
console.log(tempFilePaths[0])
//that.filename = res.tempFiles[0].name
//将保存在微信暂存区的文件上传到你项目的保存地址
//将保存在微信暂存区的文件上传到你项目的保存地址
wx.uploadFile({
url: 'http://127.0.0.1:81/taskupload',//这里的url是你项目文件上传的接口
filePath: tempFilePaths[0].path,//这是你上传文件到微信暂存区的 路径
name: 'file',
//这里也是为小程序在真机测试校验协议时能够被通过,
//你可以直接在 data里面定义这个变量上面那个方法里面的headers可以不定义。
header:{
'Content-Type': "multipart/form-data"
},
//这个是上传文件 需要的参数,具体看你们项目接口需要提交的参数
formData: {
skey:skey,
Task_id:that.data.id
},
success (res){
const data = res.data
if(res.data == "upload successful"){
console.log("success")
}else{
console.log("fail")
}
}
})
},
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(option){
//获取通信通道
var that = this;
const eventChannel = this.getOpenerEventChannel()
// 监听acceptDataFromOpenerPage事件获取上一页面通过eventChannel传送到当前页面的数据
eventChannel.on('id', function(data) {
//对发送过来的数据进行处理
console.log(data.id)
that.setData({
id: data.id
})
})
eventChannel.on('name', function(data) {
//对发送过来的数据进行处理
console.log(data),
that.setData({
name: data.id
})
})
eventChannel.on('property', function(data) {
//对发送过来的数据进行处理
console.log(data),
that.setData({
property: data.id
})
})
//向上一页面发送数据
eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
eventChannel.emit('someEvent', {data: 'test'});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
* 与加载的区别若是返回页面则不需要加载而是调用Show方法
*/
onShow: function () {
console.log('通过缓存传递参数',wx.getStorageSync('id'))
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
submitTask: function(){
wx.navigateTo({
url: '../submit/submit',
})
},
})