index.vue 6.9 KB

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