Browse Source

upload

master
HolyKnightIX 1 year ago
parent
commit
fb1e636394
5 changed files with 180 additions and 8 deletions
  1. +72
    -1
      miniprogram/pages/index/index.js
  2. +5
    -0
      miniprogram/pages/login/login.js
  3. +101
    -4
      miniprogram/pages/upload/upload.js
  4. +1
    -2
      miniprogram/utils/request.js
  5. +1
    -1
      project.private.config.json

+ 72
- 1
miniprogram/pages/index/index.js View File

@@ -17,7 +17,6 @@ Page({


onLoad(option) { onLoad(option) {
wx.hideHomeButton() wx.hideHomeButton()

// 携带机器识别码进入 // 携带机器识别码进入
if (option.machineQrcodeId) { if (option.machineQrcodeId) {
this.setData({ this.setData({
@@ -48,22 +47,27 @@ Page({
title: '加载中', title: '加载中',
}) })
this.getImageList(10, this.data.currentIndex) this.getImageList(10, this.data.currentIndex)

} }
}, },


onShow() { onShow() {
const isLogin = wx.getStorageSync('token') const isLogin = wx.getStorageSync('token')
const isPay = wx.getStorageSync('isPay') const isPay = wx.getStorageSync('isPay')

console.log(isLogin, 'isLogin');
this.setData({ this.setData({
isLogin, isLogin,
currentIndex: 1 currentIndex: 1
}) })
if (isLogin) { if (isLogin) {
request.setHead(isLogin)
wx.showLoading({ wx.showLoading({
title: '加载中', title: '加载中',
}) })
this.getImageList(10, this.data.currentIndex) this.getImageList(10, this.data.currentIndex)
if (this.data.machineQrcodeId && !isPay) { if (this.data.machineQrcodeId && !isPay) {

this.getPayInfo(this.data.machineQrcodeId) this.getPayInfo(this.data.machineQrcodeId)
} }
} }
@@ -287,6 +291,7 @@ Page({
title: '支付成功!', title: '支付成功!',
icon: "success" icon: "success"
}) })
that.startSub()
wx.hideLoading() wx.hideLoading()
} else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) { } else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) {
clearInterval(timer) clearInterval(timer)
@@ -301,6 +306,72 @@ Page({
}) })
}, },


startSub() {
const that = this
request.get({
url: `/api/templateMsg/list?projectType=6&plat=1`
}).then(res => {
console.log(res, 'res');
const id = res.data[0].templateId

wx.showModal({
title: '订阅消息',
content: '作品生成完毕后将会通知您',
confirmColor: "",
confirmText: "好的",
showCancel: false,
complete: (res) => {
if (res.cancel) {

}

if (res.confirm) {
that.subscribe(id)
}
}
})
}).catch(err => {
console.log(err, 'err');
})
},

subscribe(templateId) {
const arr = [templateId]
wx.requestSubscribeMessage({
//此处填写刚才申请模板的模板ID
tmplIds: arr,
success(res) {
console.log(res);
let failFlag = true;
arr.forEach((item) => {
if (res[item] == "accept") {
wx.showToast({
title: "订阅成功",
icon: "success",
});
failFlag = false;
}
});
if (failFlag) {
wx.showModal({
title: "提示",
content:
"订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能",
confirmText: "确定",
showCancel: false,
});
}
},
fail(err) {
console.log("订阅消息失败", err);
wx.showToast({
title: "订阅失败",
icon: "none",
});
},
});
},

onShareAppMessage() { onShareAppMessage() {
const promise = new Promise(resolve => { const promise = new Promise(resolve => {
setTimeout(() => { setTimeout(() => {


+ 5
- 0
miniprogram/pages/login/login.js View File

@@ -112,6 +112,11 @@ Page({
data data
}).then(res => { }).then(res => {
// 获取手机号之后,绑定用户与机器 // 获取手机号之后,绑定用户与机器
if (res.data.token) {
wx.setStorageSync('token', res.data.token)
request.setHead(res.data.token)
}

that.bindUser() that.bindUser()
}).catch(err => { }).catch(err => {
console.log(err, 'err'); console.log(err, 'err');


+ 101
- 4
miniprogram/pages/upload/upload.js View File

@@ -43,7 +43,7 @@ Page({


chooseImage(e) { chooseImage(e) {
const that = this const that = this
const action = e.currentTarget.dataset.action
const action = e ? e.currentTarget.dataset.action : false


if (action && that.data.tempFilePath) { if (action && that.data.tempFilePath) {
that.setData({ that.setData({
@@ -77,6 +77,10 @@ Page({
const filePath = that.data.tempFilePath const filePath = that.data.tempFilePath
const BaseUrl = request.baseUrl const BaseUrl = request.baseUrl


wx.showLoading({
title: '检测中 1/3',
})

wx.uploadFile({ wx.uploadFile({
filePath, filePath,
url: BaseUrl + "/api/userDigital/checkPhoto", url: BaseUrl + "/api/userDigital/checkPhoto",
@@ -89,6 +93,7 @@ Page({
if (code == 200) { if (code == 200) {
that.imgCheckByBaidu() that.imgCheckByBaidu()
} else { } else {
wx.hideLoading()
that.setData({ that.setData({
showScanLine: false showScanLine: false
}) })
@@ -99,6 +104,7 @@ Page({
} }
}, },
fail: err => { fail: err => {
wx.hideLoading()
wx.showToast({ wx.showToast({
title: '上传失败,请稍后再试', title: '上传失败,请稍后再试',
icon: "none" icon: "none"
@@ -113,6 +119,10 @@ Page({
const filePath = that.data.tempFilePath const filePath = that.data.tempFilePath
const BaseUrl = request.baseUrl const BaseUrl = request.baseUrl


wx.showLoading({
title: '验证中 2/3',
})

wx.uploadFile({ wx.uploadFile({
filePath, filePath,
url: BaseUrl + "/api/baidu/checkPhoto", url: BaseUrl + "/api/baidu/checkPhoto",
@@ -125,6 +135,7 @@ Page({
if (code == 200) { if (code == 200) {
that.doUploadImg() that.doUploadImg()
} else { } else {
wx.hideLoading()
that.setData({ that.setData({
showScanLine: false showScanLine: false
}) })
@@ -135,6 +146,7 @@ Page({
} }
}, },
fail: err => { fail: err => {
wx.hideLoading()
wx.showToast({ wx.showToast({
title: '上传失败,请稍后再试', title: '上传失败,请稍后再试',
icon: "none" icon: "none"
@@ -149,6 +161,10 @@ Page({
const filePath = that.data.tempFilePath const filePath = that.data.tempFilePath
const BaseUrl = request.baseUrl const BaseUrl = request.baseUrl


wx.showLoading({
title: '上传中 3/3',
})

wx.uploadFile({ wx.uploadFile({
filePath, filePath,
url: BaseUrl + "/api/upload/awsImgUpload", url: BaseUrl + "/api/upload/awsImgUpload",
@@ -163,26 +179,41 @@ Page({
console.log(res, 'res'); console.log(res, 'res');
const data = JSON.parse(res.data) const data = JSON.parse(res.data)
if (data.code == 200) { if (data.code == 200) {
wx.hideLoading()
that.setData({ that.setData({
showScanLine: false, showScanLine: false,
isSuccess: true, isSuccess: true,
onlineFilePath: data.data.url onlineFilePath: data.data.url
}) })
wx.showToast({
title: '上传成功!',
icon: "success"
wx.showModal({
title: '照片验证成功!',
content: '是否要使用这张照片?',
confirmText: "使用",
confirmColor: "#ff4f00",
cancelText: "换一张",
complete: (res) => {
if (res.cancel) {
that.chooseImage(false)
}

if (res.confirm) {
that.confirmImage()
}
}
}) })
} else { } else {
wx.showToast({ wx.showToast({
title: '服务器繁忙,请稍后再试', title: '服务器繁忙,请稍后再试',
icon: "none" icon: "none"
}) })
wx.hideLoading()
that.setData({ that.setData({
showScanLine: false showScanLine: false
}) })
} }
}, },
fail: err => { fail: err => {
wx.hideLoading()
wx.showToast({ wx.showToast({
title: '上传失败,请稍后再试', title: '上传失败,请稍后再试',
icon: "none" icon: "none"
@@ -212,12 +243,78 @@ Page({
that.setData({ that.setData({
topTitle: "上传成功!" topTitle: "上传成功!"
}) })
that.startSub()
} }
}).catch(err => { }).catch(err => {
console.log(err, 'err'); console.log(err, 'err');
}) })
}, },


startSub() {
const that = this
request.get({
url: `/api/templateMsg/list?projectType=6&plat=1`
}).then(res => {
console.log(res, 'res');
const id = res.data[0].templateId
wx.showModal({
title: '订阅消息',
content: '作品生成完毕后将会通知您',
confirmColor: "",
confirmText: "好的",
showCancel: false,
complete: (res) => {
if (res.cancel) {

}

if (res.confirm) {
that.subscribe(id)
}
}
})
}).catch(err => {
console.log(err, 'err');
})
},

subscribe(templateId) {
const arr = [templateId]
wx.requestSubscribeMessage({
//此处填写刚才申请模板的模板ID
tmplIds: arr,
success(res) {
console.log(res);
let failFlag = true;
arr.forEach((item) => {
if (res[item] == "accept") {
wx.showToast({
title: "订阅成功",
icon: "success",
});
failFlag = false;
}
});
if (failFlag) {
wx.showModal({
title: "提示",
content:
"订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能",
confirmText: "确定",
showCancel: false,
});
}
},
fail(err) {
console.log("订阅消息失败", err);
wx.showToast({
title: "订阅失败",
icon: "none",
});
},
});
},

/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */


+ 1
- 2
miniprogram/utils/request.js View File

@@ -33,9 +33,8 @@ class request {
* @description 设置请求头 * @description 设置请求头
* @param {*} data token , tenantId * @param {*} data token , tenantId
*/ */
setHead(token, tenantId) {
setHead(token) {
this.headers.token = token; this.headers.token = token;
this.headers.tenantId = tenantId;
} }


/** /**


+ 1
- 1
project.private.config.json View File

@@ -12,7 +12,7 @@
{ {
"name": "", "name": "",
"pathName": "pages/login/login", "pathName": "pages/login/login",
"query": "scene=865789927095844864",
"query": "scene=866529281119674368",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },


Loading…
Cancel
Save