运维小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/personalInfo/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. user:'',
  9. identitycard:"",
  10. fileurl:'',
  11. back:"",
  12. Peakprice:""
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. // this.gituser()
  19. },
  20. gituser(){
  21. api.request(`/toolprogram/selectuser`, 'POST',{})
  22. .then((res) => {
  23. console.log(res);
  24. this.setData({
  25. user:res.data,
  26. fileurl:res.data.userfrontofidcard,
  27. back:res.data.userreverseofidcard
  28. })
  29. })
  30. .catch((err) => {
  31. console.error('请求失败:', err);
  32. // 在这里处理请求失败的情况
  33. });
  34. },
  35. // 上传头像
  36. bindtoImage(){
  37. let _this = this
  38. // 先检查隐私授权状态
  39. wx.getPrivacySetting({
  40. success: (res) => {
  41. if (res.needAuthorization) {
  42. // 弹出隐私协议弹窗
  43. wx.requirePrivacyAuthorize({
  44. success: () => {
  45. console.log('用户已同意隐私协议');
  46. _this.choosetoImage(); // 继续执行上传
  47. },
  48. fail: () => {
  49. console.log('用户拒绝了隐私协议');
  50. wx.showToast({
  51. title: '需同意隐私协议才能使用',
  52. icon: 'none'
  53. });
  54. }
  55. });
  56. } else {
  57. _this.choosetoImage(); // 已授权,直接上传
  58. }
  59. }
  60. });
  61. },
  62. // 上传头像图片
  63. choosetoImage() {
  64. let _this = this
  65. wx.chooseMedia({
  66. count: 1,
  67. mediaType: ['image','video'],
  68. sourceType: ['album', 'camera'],
  69. success(res) {
  70. console.log(res);
  71. const tempFiles = res.tempFiles;
  72. _this.setData({
  73. imageList: tempFiles.map(file => file.tempFilePath),
  74. });
  75. _this.uploadtoImages(tempFiles);
  76. },
  77. fail(err) {
  78. console.error("选择失败:", err);
  79. }
  80. })
  81. },
  82. // 上传到服务器
  83. uploadtoImages(files) {
  84. let _this =this
  85. const token = wx.getStorageSync('token');
  86. files.forEach((file) => {
  87. wx.uploadFile({
  88. url: 'https://esos-iot.com:8443/toolprogram/upload/webPost',
  89. filePath: file.tempFilePath,
  90. name: 'file',
  91. formData: {
  92. file:file.tempFilePath
  93. },
  94. header: {
  95. 'Authorization': 'Bearer ' + token // Also add to header if needed
  96. },
  97. success: (res) => {
  98. console.log(res);
  99. const obj = JSON.parse(res.data);
  100. let data ={
  101. userprofile:obj.data.userprofile,
  102. }
  103. api.request(`/toolprogram/insertpartner`, 'POST',data)
  104. .then((res) => {
  105. console.log(res);
  106. this.setData({
  107. user:res.data,
  108. fileurl:res.data.userfrontofidcard,
  109. back:res.data.userreverseofidcard
  110. })
  111. wx.showToast({
  112. title: res.msg,
  113. icon: 'none'
  114. });
  115. })
  116. .catch((err) => {
  117. console.error('请求失败:', err);
  118. // 在这里处理请求失败的情况
  119. });
  120. },
  121. fail: (err) => {
  122. console.error('上传失败', err);
  123. },
  124. });
  125. });
  126. },
  127. /**
  128. * 生命周期函数--监听页面初次渲染完成
  129. */
  130. onReady() {
  131. },
  132. /**
  133. * 生命周期函数--监听页面显示
  134. */
  135. onShow() {
  136. },
  137. /**
  138. * 生命周期函数--监听页面隐藏
  139. */
  140. onHide() {
  141. },
  142. /**
  143. * 生命周期函数--监听页面卸载
  144. */
  145. onUnload() {
  146. },
  147. /**
  148. * 页面相关事件处理函数--监听用户下拉动作
  149. */
  150. onPullDownRefresh() {
  151. },
  152. /**
  153. * 页面上拉触底事件的处理函数
  154. */
  155. onReachBottom() {
  156. },
  157. /**
  158. * 用户点击右上角分享
  159. */
  160. onShareAppMessage() {
  161. }
  162. })