index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="product-window" :class="{'on':isShow}">
  4. <view class="iconfont icon-guanbi" @click="closeAttr"></view>
  5. <view class="mp-data">
  6. <image :src="mpData.siteLogo" mode=""></image>
  7. <text class="mp-name">{{mpData.siteName}} 申请</text>
  8. </view>
  9. <view class="trip-msg">
  10. <view class="title">
  11. {{$t(`获取您的昵称、头像`)}}
  12. </view>
  13. <view class="trip">
  14. {{$t(`提供具有辨识度的用户中心界面`)}}
  15. </view>
  16. </view>
  17. <form @submit="formSubmit">
  18. <view class="edit">
  19. <view class="avatar edit-box">
  20. <view class="left">
  21. <view class="head">{{$t(`头像`)}}</view>
  22. <!-- <image :src="userInfo.avatar || defaultAvatar" mode=""></image> -->
  23. <view class="avatar-box" v-if="!mp_is_new" @click.stop='uploadpic'>
  24. <image :src="userInfo.avatar || defHead"></image>
  25. </view>
  26. <button v-else class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  27. <image :src="userInfo.avatar || defHead"></image>
  28. </button>
  29. </view>
  30. <!-- <view class="iconfont icon-xiangyou"></view> -->
  31. </view>
  32. <view class="nickname edit-box">
  33. <view class="left">
  34. <view class="head">{{$t(`昵称`)}}</view>
  35. <view class='input'><input type='nickname' placeholder-class="pl-sty"
  36. :placeholder="$t(`请输入昵称`)" name='nickname' :maxlength="16"
  37. :value='userInfo.nickname'></input>
  38. </view>
  39. </view>
  40. <!-- <view class="iconfont icon-xiangyou"></view> -->
  41. </view>
  42. </view>
  43. <view class="bottom">
  44. <button class="save" formType="submit" :class="{'open': userInfo.avatar}">
  45. {{$t(`保存`)}}
  46. </button>
  47. </view>
  48. </form>
  49. </view>
  50. <canvas canvas-id="canvas" v-if="canvasStatus"
  51. :style="{width: canvasWidth + 'px', height: canvasHeight + 'px',position: 'absolute',left:'-100000px',top:'-100000px'}"></canvas>
  52. <view class="mask" @touchmove.prevent v-if="isShow" @click="closeAttr"></view>
  53. </view>
  54. </uni-popup>
  55. </template>
  56. <script>
  57. import colors from "@/mixins/color";
  58. import Cache from '@/utils/cache';
  59. import {
  60. userEdit,
  61. } from '@/api/user.js';
  62. export default {
  63. mixins: [colors],
  64. props: {
  65. isShow: {
  66. type: Boolean,
  67. default: false
  68. }
  69. },
  70. data() {
  71. return {
  72. defHead: require('@/static/images/def_avatar.png'),
  73. mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false,
  74. userInfo: {
  75. avatar: '',
  76. nickname: '',
  77. },
  78. mpData: uni.getStorageSync('copyRight'),
  79. canvasStatus: false,
  80. };
  81. },
  82. mounted() {
  83. },
  84. methods: {
  85. /**
  86. * 上传文件
  87. *
  88. */
  89. uploadpic: function() {
  90. let that = this;
  91. this.canvasStatus = true
  92. that.$util.uploadImageChange('upload/image', (res) => {
  93. let userInfo = that.userInfo;
  94. if (userInfo !== undefined) {
  95. that.userInfo.avatar = res.data.url;
  96. }
  97. this.canvasStatus = false
  98. }, (res) => {
  99. this.canvasStatus = false
  100. }, (res) => {
  101. this.canvasWidth = res.w
  102. this.canvasHeight = res.h
  103. });
  104. },
  105. // 微信头像获取
  106. onChooseAvatar(e) {
  107. const {
  108. avatarUrl
  109. } = e.detail
  110. this.$util.uploadImgs('upload/image', avatarUrl, (res) => {
  111. this.userInfo.avatar = res.data.url
  112. }, (err) => {
  113. console.log(err)
  114. })
  115. },
  116. closeAttr: function() {
  117. this.$emit('closeEdit');
  118. },
  119. /**
  120. * 提交修改
  121. */
  122. formSubmit(e) {
  123. let that = this
  124. if (!this.userInfo.avatar) return that.$util.Tips({
  125. title: that.$t(`请上传头像`)
  126. });
  127. if (!e.detail.value.nickname) return that.$util.Tips({
  128. title: that.$t(`请输入昵称`)
  129. });
  130. this.userInfo.nickname = e.detail.value.nickname
  131. userEdit(this.userInfo).then(res => {
  132. this.$emit('editSuccess')
  133. return that.$util.Tips({
  134. title: res.msg,
  135. icon: 'success'
  136. }, {
  137. tab: 3
  138. });
  139. }).catch(msg => {
  140. return that.$util.Tips({
  141. title: msg || that.$t(`保存失败`)
  142. }, {
  143. tab: 3,
  144. url: 1
  145. });
  146. });
  147. }
  148. }
  149. }
  150. </script>
  151. <style>
  152. .pl-sty {
  153. color: #999999;
  154. font-size: 30rpx;
  155. }
  156. </style>
  157. <style scoped lang="scss">
  158. .product-window.on {
  159. transform: translate3d(0, 0, 0);
  160. }
  161. .mask {
  162. z-index: 99;
  163. }
  164. .product-window {
  165. position: fixed;
  166. bottom: 0;
  167. width: 100%;
  168. left: 0;
  169. background-color: #fff;
  170. z-index: 1000;
  171. border-radius: 20rpx 20rpx 0 0;
  172. transform: translate3d(0, 100%, 0);
  173. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  174. padding: 38rpx 40rpx;
  175. padding-bottom: 80rpx;
  176. padding-bottom: calc(80rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  177. padding-bottom: calc(80rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  178. .icon-guanbi {
  179. position: absolute;
  180. top: 40rpx;
  181. right: 40rpx;
  182. font-size: 24rpx;
  183. font-weight: bold;
  184. color: #999;
  185. }
  186. .mp-data {
  187. display: flex;
  188. align-items: center;
  189. margin-bottom: 30rpx;
  190. .mp-name {
  191. font-size: 28rpx;
  192. font-weight: bold;
  193. color: #000000;
  194. }
  195. image {
  196. width: 48rpx;
  197. height: 48rpx;
  198. border-radius: 50%;
  199. margin-right: 16rpx;
  200. }
  201. }
  202. .trip-msg {
  203. padding-bottom: 32rpx;
  204. border-bottom: 1px solid #F5F5F5;
  205. .title {
  206. font-size: 30rpx;
  207. font-weight: bold;
  208. color: #000;
  209. margin-bottom: 6rpx;
  210. }
  211. .trip {
  212. font-size: 26rpx;
  213. color: #777777;
  214. }
  215. }
  216. .edit {
  217. border-bottom: 1px solid #F5F5F5;
  218. .avatar {
  219. border-bottom: 1px solid #F5F5F5;
  220. }
  221. .nickname {
  222. .input {
  223. width: 100%;
  224. }
  225. input {
  226. height: 80rpx;
  227. }
  228. }
  229. .edit-box {
  230. display: flex;
  231. justify-content: space-between;
  232. align-items: center;
  233. font-size: 30rpx;
  234. padding: 22rpx 0;
  235. .left {
  236. display: flex;
  237. align-items: center;
  238. flex: 1;
  239. .head {
  240. color: rgba(0, 0, 0, 0.9);
  241. white-space: nowrap;
  242. margin-right: 60rpx;
  243. }
  244. button {
  245. flex: 1;
  246. display: flex;
  247. align-items: center;
  248. }
  249. }
  250. image {
  251. width: 80rpx;
  252. height: 80rpx;
  253. border-radius: 6rpx;
  254. }
  255. }
  256. .icon-xiangyou {
  257. color: #cfcfcf;
  258. }
  259. }
  260. .bottom {
  261. display: flex;
  262. align-items: center;
  263. justify-content: center;
  264. .save {
  265. border: 1px solid #F5F5F5;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. width: 368rpx;
  270. height: 80rpx;
  271. border-radius: 12rpx;
  272. margin-top: 52rpx;
  273. background-color: #F5F5F5;
  274. color: #ccc;
  275. font-size: 30rpx;
  276. font-weight: bold;
  277. }
  278. .save.open {
  279. border: 1px solid #fff;
  280. background-color: #07C160;
  281. color: #fff;
  282. }
  283. }
  284. }
  285. </style>