| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- // pages/personalInfo/index.js
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- user:'',
- identitycard:"",
- fileurl:'',
- back:"",
- Peakprice:""
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // this.gituser()
- },
- gituser(){
- api.request(`/toolprogram/selectuser`, 'POST',{})
- .then((res) => {
- console.log(res);
- this.setData({
- user:res.data,
- fileurl:res.data.userfrontofidcard,
- back:res.data.userreverseofidcard
- })
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 上传头像
- bindtoImage(){
- let _this = this
- // 先检查隐私授权状态
- wx.getPrivacySetting({
- success: (res) => {
- if (res.needAuthorization) {
- // 弹出隐私协议弹窗
- wx.requirePrivacyAuthorize({
- success: () => {
- console.log('用户已同意隐私协议');
- _this.choosetoImage(); // 继续执行上传
- },
- fail: () => {
- console.log('用户拒绝了隐私协议');
- wx.showToast({
- title: '需同意隐私协议才能使用',
- icon: 'none'
- });
- }
- });
- } else {
- _this.choosetoImage(); // 已授权,直接上传
- }
- }
- });
- },
- // 上传头像图片
- choosetoImage() {
- let _this = this
- wx.chooseMedia({
- count: 1,
- mediaType: ['image','video'],
- sourceType: ['album', 'camera'],
- success(res) {
- console.log(res);
- const tempFiles = res.tempFiles;
- _this.setData({
- imageList: tempFiles.map(file => file.tempFilePath),
- });
- _this.uploadtoImages(tempFiles);
- },
- fail(err) {
- console.error("选择失败:", err);
- }
- })
- },
- // 上传到服务器
- uploadtoImages(files) {
- let _this =this
- const token = wx.getStorageSync('token');
- files.forEach((file) => {
- wx.uploadFile({
- url: 'https://esos-iot.com:8443/toolprogram/upload/webPost',
- filePath: file.tempFilePath,
- name: 'file',
- formData: {
- file:file.tempFilePath
- },
- header: {
- 'Authorization': 'Bearer ' + token // Also add to header if needed
- },
- success: (res) => {
- console.log(res);
- const obj = JSON.parse(res.data);
-
- let data ={
- userprofile:obj.data.userprofile,
- }
- api.request(`/toolprogram/insertpartner`, 'POST',data)
- .then((res) => {
- console.log(res);
- this.setData({
- user:res.data,
- fileurl:res.data.userfrontofidcard,
- back:res.data.userreverseofidcard
- })
- wx.showToast({
- title: res.msg,
- icon: 'none'
- });
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- fail: (err) => {
- console.error('上传失败', err);
- },
- });
- });
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|