myInfo.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="my-info">
  3. <!-- 导航区域 -->
  4. <view class="icon-title-navBar-box">
  5. <view @click="handleBack" class="nav-bar-icon"></view>
  6. <text class="nav-bar-title">个人信息</text>
  7. </view>
  8. <!-- 头像 -->
  9. <view>
  10. <uni-file-picker limit="1" :del-icon="false" disable-preview :imageStyles="imageStyles" :auto-upload="false"
  11. @select="handleSelect" file-mediatype="image">选择</uni-file-picker>
  12. <view>图片地址:{{data.icon}}</view>
  13. </view>
  14. <!-- 姓名 -->
  15. <view></view>
  16. <!-- 证件号 -->
  17. <view></view>
  18. <!-- 电话 -->
  19. <view></view>
  20. <!-- 性别 -->
  21. <view></view>
  22. <button @click="handleUpdate">更新</button>
  23. </view>
  24. </template>
  25. <script setup>
  26. import * as myApi from "@/api/my.js";
  27. import {
  28. getAliyunPolicy
  29. } from "@/api/jiazheng.js"
  30. import {
  31. ref,
  32. reactive
  33. } from "vue"
  34. import {
  35. onLoad
  36. } from "@dcloudio/uni-app"
  37. const imageStyles = ref({
  38. width: 64,
  39. height: 64,
  40. border: {
  41. radius: '50%'
  42. }
  43. });
  44. const data = reactive({
  45. from: 'shouye', // my | kaoshi | shouye
  46. gender: 0,
  47. icon: '',
  48. realName: '',
  49. idcard: '',
  50. userName: '',
  51. userId: null
  52. })
  53. onLoad((options) => {
  54. data.from = options.from || 'shouye';
  55. initPage();
  56. })
  57. function handleSelect(e) {
  58. doUploadImage(e.tempFilePaths[0])
  59. }
  60. function doUploadImage(filePath) {
  61. const loading = uni.showLoading({
  62. title: '上传中...',
  63. mask: true
  64. });
  65. try {
  66. const suffix = filePath.split('.').pop();
  67. let req = {
  68. prefix: 'resource/',
  69. suffix: suffix
  70. }
  71. getAliyunPolicy(req).then(res => {
  72. if (res.code == 0) {
  73. const policyData = res.data;
  74. const formData = {
  75. key: policyData.key,
  76. policy: policyData.policy,
  77. OSSAccessKeyId: policyData.accessid,
  78. signature: policyData.signature,
  79. success_action_status: '200',
  80. file: {
  81. name: policyData.key,
  82. uri: filePath
  83. }
  84. };
  85. uni.uploadFile({
  86. url: policyData.uploadUrl,
  87. filePath: filePath,
  88. name: 'file',
  89. formData: formData,
  90. header: {
  91. 'Content-Type': 'multipart/form-data'
  92. },
  93. success(uploadRes) {
  94. if (uploadRes.statusCode === 200) {
  95. data.icon = `${policyData.downloadUrl}/${policyData.key}`;
  96. uni.showToast({
  97. title: '上传成功',
  98. icon: 'success'
  99. });
  100. } else {
  101. uni.showToast({
  102. title: '上传失败',
  103. });
  104. }
  105. uni.hideLoading();
  106. },
  107. fail(err) {
  108. uni.showToast({
  109. title: '上传失败',
  110. });
  111. uni.hideLoading();
  112. }
  113. });
  114. } else {
  115. uni.showToast({
  116. title: '获取凭证失败',
  117. });
  118. uni.hideLoading();
  119. }
  120. })
  121. } catch (error) {
  122. uni.showToast({
  123. title: '上传失败',
  124. icon: 'none'
  125. });
  126. uni.hideLoading();
  127. }
  128. }
  129. function handleUpdate() {
  130. myApi.getUserUpdate({}).then(res => {
  131. if (res.data) {
  132. uni.showToast({
  133. title: '更新成功'
  134. })
  135. }
  136. })
  137. }
  138. function handleBack() {
  139. if (data.from == 'my') {
  140. uni.redirectTo({
  141. url: '/pages/client/my/index'
  142. })
  143. } else if (data.from == 'kaoshi') {
  144. uni.redirectTo({
  145. url: '/pages/client/ShouYe/shouye'
  146. })
  147. } else {
  148. uni.redirectTo({
  149. url: '/pages/client/ShouYe/shouye'
  150. })
  151. }
  152. }
  153. function initPage() {
  154. myApi.getMineUser().then(res => {
  155. const {
  156. gender,
  157. icon,
  158. idcard,
  159. realName,
  160. userName,
  161. userId
  162. } = res.data;
  163. })
  164. }
  165. </script>
  166. <style>
  167. </style>