index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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.site_logo" mode=""></image>
  7. <text class="mp-name">{{mpData.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 || 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">昵称</view>
  35. <view class='input'><input type='nickname' :always-embed="true" :adjust-position="true" cursor-spacing="30" placeholder-class="pl-sty"
  36. placeholder="请输入昵称" 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. 保存
  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. import {
  63. copyRight
  64. } from '@/api/api.js';
  65. export default {
  66. mixins: [colors],
  67. props: {
  68. isShow: {
  69. type: Boolean,
  70. value: false
  71. }
  72. },
  73. data() {
  74. return {
  75. defHead: require('@/static/images/def_avatar.png'),
  76. mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false,
  77. userInfo: {
  78. avatar: '',
  79. nickname: '',
  80. },
  81. mpData: {
  82. site_logo: '',
  83. site_name: ''
  84. },
  85. canvasStatus: false,
  86. configData: this.$Cache.get('BASIC_CONFIG')
  87. };
  88. },
  89. mounted() {
  90. try{
  91. let MPSiteData = uni.getStorageSync('MPSiteData');
  92. if (MPSiteData) {
  93. this.mpData = JSON.parse(MPSiteData);
  94. } else{
  95. this.getCopyRight();
  96. }
  97. }catch(e){
  98. //TODO handle the exception
  99. }
  100. },
  101. methods: {
  102. getCopyRight(){
  103. copyRight().then(res => {
  104. let { site_logo, site_name } = res.data;
  105. this.mpData.site_logo = site_logo;
  106. this.mpData.site_name = site_name;
  107. uni.setStorageSync('MPSiteData', JSON.stringify(this.mpData));
  108. }).catch(err => {
  109. return this.$util.Tips({
  110. title: err.msg
  111. });
  112. });
  113. },
  114. /**
  115. * 上传文件
  116. *
  117. */
  118. uploadpic: function() {
  119. let that = this;
  120. this.canvasStatus = true
  121. that.$util.uploadImageChange('upload/image', (res) => {
  122. let userInfo = that.userInfo;
  123. if (userInfo !== undefined) {
  124. that.userInfo.avatar = res.data.url;
  125. }
  126. this.canvasStatus = false
  127. }, (res) => {
  128. this.canvasStatus = false
  129. }, (res) => {
  130. this.canvasWidth = res.w
  131. this.canvasHeight = res.h
  132. });
  133. },
  134. // 微信头像获取
  135. onChooseAvatar(e) {
  136. const {
  137. avatarUrl
  138. } = e.detail
  139. this.$util.uploadImgs('upload/image', avatarUrl, (res) => {
  140. this.userInfo.avatar = res.data.url
  141. }, (err) => {
  142. console.log(err)
  143. })
  144. },
  145. closeAttr: function() {
  146. this.$emit('closeEdit');
  147. },
  148. /**
  149. * 提交修改
  150. */
  151. formSubmit(e) {
  152. let that = this
  153. if (!this.userInfo.avatar) return that.$util.Tips({
  154. title: '请上传头像'
  155. });
  156. if (!e.detail.value.nickname) return that.$util.Tips({
  157. title: '请输入昵称'
  158. });
  159. this.userInfo.nickname = e.detail.value.nickname
  160. userEdit(this.userInfo).then(res => {
  161. this.$emit('editSuccess')
  162. return that.$util.Tips({
  163. title: res.msg,
  164. icon: 'success'
  165. }, {
  166. tab: 3,
  167. url: this.configData.wechat_auth_switch ? 2 : 1
  168. });
  169. }).catch(msg => {
  170. return that.$util.Tips({
  171. title: msg || '保存失败'
  172. });
  173. });
  174. }
  175. }
  176. }
  177. </script>
  178. <style>
  179. .pl-sty {
  180. color: #999999;
  181. font-size: 30rpx;
  182. }
  183. </style>
  184. <style scoped lang="scss">
  185. .product-window.on {
  186. transform: translate3d(0, 0, 0);
  187. }
  188. .mask {
  189. z-index: 100;
  190. }
  191. .product-window {
  192. position: fixed;
  193. bottom: 0;
  194. width: 100%;
  195. left: 0;
  196. background-color: #fff;
  197. z-index: 1000;
  198. border-radius: 20rpx 20rpx 0 0;
  199. transform: translate3d(0, 100%, 0);
  200. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  201. padding: 38rpx 40rpx;
  202. padding-bottom: 80rpx;
  203. padding-bottom: calc(80rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  204. padding-bottom: calc(80rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  205. .icon-guanbi {
  206. position: absolute;
  207. top: 30rpx;
  208. right: 30rpx;
  209. font-size: 24rpx;
  210. font-weight: bold;
  211. color: #999;
  212. padding: 10rpx;
  213. }
  214. .mp-data {
  215. display: flex;
  216. align-items: center;
  217. margin-bottom: 30rpx;
  218. .mp-name {
  219. font-size: 28rpx;
  220. font-weight: bold;
  221. color: #000000;
  222. }
  223. image {
  224. width: 48rpx;
  225. height: 48rpx;
  226. border-radius: 50%;
  227. margin-right: 16rpx;
  228. }
  229. }
  230. .trip-msg {
  231. padding-bottom: 32rpx;
  232. border-bottom: 1px solid #F5F5F5;
  233. .title {
  234. font-size: 30rpx;
  235. font-weight: bold;
  236. color: #000;
  237. margin-bottom: 6rpx;
  238. }
  239. .trip {
  240. font-size: 26rpx;
  241. color: #777777;
  242. }
  243. }
  244. .edit {
  245. border-bottom: 1px solid #F5F5F5;
  246. .avatar {
  247. border-bottom: 1px solid #F5F5F5;
  248. }
  249. .nickname {
  250. .input {
  251. width: 100%;
  252. }
  253. input {
  254. height: 80rpx;
  255. }
  256. }
  257. .edit-box {
  258. display: flex;
  259. justify-content: space-between;
  260. align-items: center;
  261. font-size: 30rpx;
  262. padding: 22rpx 0;
  263. .left {
  264. display: flex;
  265. align-items: center;
  266. flex: 1;
  267. .head {
  268. color: rgba(0, 0, 0, 0.9);
  269. white-space: nowrap;
  270. margin-right: 60rpx;
  271. }
  272. button {
  273. flex: 1;
  274. display: flex;
  275. align-items: center;
  276. }
  277. }
  278. image {
  279. width: 80rpx;
  280. height: 80rpx;
  281. border-radius: 6rpx;
  282. }
  283. }
  284. .icon-xiangyou {
  285. color: #cfcfcf;
  286. }
  287. }
  288. .bottom {
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. .save {
  293. border: 1px solid #F5F5F5;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. width: 368rpx;
  298. height: 80rpx;
  299. border-radius: 12rpx;
  300. margin-top: 52rpx;
  301. background-color: #F5F5F5;
  302. color: #ccc;
  303. font-size: 30rpx;
  304. font-weight: bold;
  305. }
  306. .save.open {
  307. border: 1px solid #fff;
  308. background-color: var(--view-theme);
  309. color: #fff;
  310. }
  311. }
  312. }
  313. </style>