index.vue 7.1 KB

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