userinfo.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view class="containar">
  7. <view class="avatarUrl">
  8. <view>
  9. <button type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseAvatar"
  10. style="width: 200rpx;height: 200rpx;padding: 0;">
  11. <image :src="avatarUrl" class="refreshIcon"></image>
  12. </button>
  13. </view>
  14. </view>
  15. <view class="nickname">
  16. <view>昵称:</view>
  17. <view>
  18. <input type="nickname" class="weui-input" :value="nickName" @blur="bindblur" placeholder="请输入昵称"
  19. @input="bindinput" />
  20. </view>
  21. </view>
  22. <button class="btn1" @click="submitForm()">保存</button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import mvBar from "@/components/mys_navBar/mysNavBar";
  28. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  29. import getPolicyEncode from '@/components/obs/getPolicy.js';
  30. import getSignature from '@/components/obs/GetSignature.js';
  31. export default {
  32. components: {
  33. mvBar,
  34. htzImageUpload,
  35. },
  36. data() {
  37. return {
  38. navH: getApp().globalData.navHeight,
  39. avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
  40. nickName: '',
  41. mysNavConfig: {
  42. /* 开启单页显示首页图标 */
  43. isHome: true,
  44. /* 固定导航 */
  45. navFixed: true,
  46. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  47. navTitle: {
  48. text: "个人信息",
  49. color: "",
  50. fontSize: "32rpx", // px upx rpx
  51. fontWeight: "normal", // 100 - 700
  52. },
  53. btnType: "type2",
  54. onLeftClick: "/pages/mycenter/mycenter",
  55. /* type2 按钮 */
  56. type2Config: {
  57. // 左图标
  58. leftPath: "/static/img/png2.png",
  59. // 右图标
  60. rightPath: "/static/img/png4.png",
  61. // 圆角
  62. radius: "40rpx",
  63. },
  64. },
  65. }
  66. },
  67. onShow() {
  68. this.nickName = uni.getStorageSync('nickName');
  69. this.avatarUrl = uni.getStorageSync('avatarUrl');
  70. },
  71. methods: {
  72. bindblur(e) {
  73. this.nickName = e.detail.value; // 获取微信昵称
  74. },
  75. bindinput(e) {
  76. this.nickName = e.detail.value; //这里要注意如果只用blur方法的话用户在输入玩昵称后直接点击保存按钮,会出现修改不成功的情况。
  77. },
  78. onChooseAvatar(e) {
  79. // console.log("111", e)
  80. // return
  81. let {
  82. avatarUrl
  83. } = e.detail;
  84. this.store = 'talent_upload/avatar/' + this.guid() + '.png'
  85. this.imgUpload(avatarUrl);
  86. },
  87. async submitForm() {
  88. if (this.nickName === '') {
  89. uni.showToast({
  90. icon: 'none',
  91. title: '请输入昵称'
  92. })
  93. return false;
  94. }
  95. uni.setStorageSync('avatarUrl', this.avatarUrl);
  96. uni.setStorageSync('nickName', this.nickName);
  97. // 更新数据库中昵称
  98. await this.$https.post('/youngee/c/t/p/update-talent-info', {
  99. talent_wx_nickname: this.nickName,
  100. avatar: this.avatarUrl
  101. })
  102. .then(res => {
  103. console.log(res)
  104. })
  105. uni.navigateBack()
  106. },
  107. imgUpload(tempFilePath) {
  108. uni.showLoading({
  109. title: '加载中'
  110. });
  111. let that = this
  112. console.log('imgUpload', tempFilePath)
  113. let config = {
  114. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  115. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  116. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  117. };
  118. let fileName = this.store; //指定上传到OBS桶中的对象名
  119. let OBSPolicy = { //设定policy内容
  120. "expiration": "2089-12-31T12:00:00.000Z",
  121. "conditions": [{
  122. "bucket": "horastar"
  123. },
  124. {
  125. 'key': fileName
  126. }
  127. ]
  128. }
  129. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  130. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  131. uni.uploadFile({
  132. //url: config.EndPoint,
  133. url: config.EndPoint,
  134. filePath: tempFilePath,
  135. name: 'file',
  136. formData: {
  137. 'AccessKeyID': config.AccessKeyId,
  138. 'policy': policyEncoded,
  139. 'signature': signature,
  140. 'key': fileName,
  141. },
  142. success: function(res) {
  143. console.log(res.statusCode); //打印响应状态码
  144. if (res.statusCode == '204') {
  145. // that.imageData.push(config.EndPoint + '/' + fileName);
  146. console.log('上传图片成功', res)
  147. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  148. console.log(obs_url)
  149. that.avatarUrl = obs_url
  150. // uni.showToast({
  151. // title: '上传成功',
  152. // icon: '成功'
  153. // });
  154. } else {
  155. console.log('上传图片失败', res)
  156. uni.showToast({
  157. title: '上传失败',
  158. icon: '失败'
  159. });
  160. }
  161. },
  162. fail: function(e) {
  163. console.log(e);
  164. uni.showToast({
  165. title: '上传失败22222',
  166. icon: '失败'
  167. });
  168. }
  169. })
  170. uni.hideLoading();
  171. },
  172. guid() {
  173. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  174. var r = Math.random() * 16 | 0,
  175. v = c == 'x' ? r : (r & 0x3 | 0x8);
  176. return v.toString(16);
  177. });
  178. },
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .btn1 {
  184. margin: 30rpx;
  185. font-size: 35rpx;
  186. color: #000;
  187. background-color: #F0D232;
  188. border: none;
  189. border-radius: 0;
  190. }
  191. .containar {
  192. display: flex;
  193. flex-flow: column;
  194. }
  195. .avatarUrl {
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. // justify-content: space-between;
  200. }
  201. .nickname {
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. padding: 30rpx 50rpx;
  206. margin: 30rpx 0rpx;
  207. border-bottom: 1rpx solid #999999;
  208. border-top: 1rpx solid #999999;
  209. }
  210. .refreshIcon {
  211. width: 200rpx;
  212. height: 200rpx;
  213. }
  214. </style>