myInfo.vue 4.7 KB

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