userinfo.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="row b-b flex jg">
  5. <text class="tit">头像</text>
  6. <!-- <image :src="userInfo.avatar" @click.stop="imgsub"></image> -->
  7. <button type="primary" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" plain="true"
  8. style="border: none;position: relative;">
  9. <image class="avatar" :src="userInfo.avatar"></image>
  10. </button>
  11. </view>
  12. <view class="row b-b flex">
  13. <text class="tit">昵称</text>
  14. <input class="input" v-model="userInfo.nickname" type="nickname" @blur="test"
  15. placeholder-class="placeholder" />
  16. </view>
  17. <!-- #endif -->
  18. <!-- #ifndef MP-WEIXIN -->
  19. <view class="row b-b flex jg">
  20. <text class="tit">头像</text>
  21. <image class="avatar" :src="userInfo.avatar" @click.stop="imgsub"></image>
  22. </view>
  23. <view class="row b-b flex">
  24. <text class="tit">昵称</text>
  25. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  26. </view>
  27. <!-- #endif -->
  28. <view class="row">
  29. <text class="tit">手机</text>
  30. <input class="input" type="text" disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
  31. </view>
  32. <!-- <view class="row">
  33. <text class="tit">设置密码</text>
  34. <input class="input" type="text" disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
  35. </view> -->
  36. <view class="add-btn" @click="confirm">提交</view>
  37. <view class="add-btn out" @click="cancel" style="margin-top: 20rpx;">退出</view>
  38. <!-- <uni-popup ref="popup" type="center">
  39. <view class="psw-wrapper">
  40. <view class="psw-title">请输入自己的账户</view>
  41. <input type="text" v-model="password" class="psw-ipt" />
  42. <view class="psw-btn">
  43. <text @click.stop="qx">取消</text>
  44. <text class="psw-qd" @click.stop="pswQd">确定</text>
  45. </view>
  46. </view>
  47. </uni-popup> -->
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapState,
  53. mapMutations
  54. } from 'vuex';
  55. import {
  56. upload
  57. } from '@/api/order.js';
  58. import {
  59. userEdit,
  60. logout
  61. } from '@/api/set.js';
  62. import {
  63. resolve
  64. } from 'url';
  65. import {
  66. rejects
  67. } from 'assert';
  68. export default {
  69. data() {
  70. return {
  71. show: false,
  72. password: '',
  73. }
  74. },
  75. onLoad() {
  76. console.log(this.baseURL)
  77. },
  78. computed: {
  79. ...mapState('user', ['userInfo']),
  80. ...mapState(['baseURL'])
  81. },
  82. methods: {
  83. ...mapMutations('user', ['logout']),
  84. imgsub() {
  85. console.log('上传头像')
  86. upload({
  87. filename: ''
  88. }).then(data => {
  89. console.log("data", data);
  90. this.userInfo.avatar = data[0].url;
  91. })
  92. },
  93. uploadImage(image) {
  94. console.log(this.baseURL + '/api/upload/image', 'url')
  95. uni.uploadFile({
  96. url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  97. filePath: image,
  98. name: 'file',
  99. header: {
  100. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  101. },
  102. success: (uploadFileRes) => {
  103. let info
  104. if ("string" === typeof uploadFileRes.data) {
  105. info = JSON.parse(uploadFileRes.data).data
  106. } else {
  107. info = uploadFileRes.data.data
  108. }
  109. console.log(info);
  110. this.userInfo.avatar = info.url
  111. },
  112. fail(err) {
  113. console.log(err, 'err');
  114. }
  115. });
  116. },
  117. confirm() {
  118. if (this.userInfo.nickname == '微信用户') {
  119. return this.$api.msg('请修改昵称')
  120. }
  121. userEdit({
  122. avatar: this.userInfo.avatar,
  123. nickname: this.userInfo.nickname
  124. })
  125. .then(e => {
  126. this.$api.msg('修改成功');
  127. setTimeout(() => {
  128. uni.switchTab({
  129. url: '/pages/user/user'
  130. });
  131. }, 1000);
  132. console.log(e);
  133. })
  134. .catch(e => {
  135. console.log(e);
  136. });
  137. },
  138. toLogout() {
  139. let obj = this;
  140. uni.showModal({
  141. content: '确定要退出登录么',
  142. success: (e) => {
  143. if (e.confirm) {
  144. logout({}).then((e) => {
  145. uni.navigateBack();
  146. }).catch((e) => {
  147. console.log(e);
  148. })
  149. obj.logout();
  150. }
  151. }
  152. });
  153. },
  154. test(e) {
  155. console.log(e.detail, '123456');
  156. },
  157. onChooseAvatar(e) {
  158. // console.log(e.detail.avatarUrl);
  159. this.uploadImage(e.detail.avatarUrl)
  160. // this.userInfo.avatar = e.detail.avatarUrl;
  161. },
  162. cancel() {
  163. // this.$refs.popup.open();
  164. let obj = this;
  165. uni.showModal({
  166. content: '确定要退出登录么',
  167. success: e => {
  168. if (e.confirm) {
  169. logout({}).then(e => {
  170. obj.logout();
  171. uni.switchTab({
  172. url: '/pages/index/index'
  173. })
  174. })
  175. .catch(e => {
  176. console.log(e);
  177. });
  178. }
  179. }
  180. });
  181. },
  182. qx() {
  183. this.password = '';
  184. this.$refs.popup.close();
  185. },
  186. pswQd() {
  187. if (this.password != this.userInfo.phone) {
  188. this.$refs.popup.close();
  189. this.password = '';
  190. this.$api.msg("请输入自己的账户")
  191. return
  192. }
  193. this.$refs.popup.close();
  194. this.password = '';
  195. this.$api.msg("申请注销成功,请耐心等待审核")
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. .row1 {
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. position: relative;
  206. padding: 0 30upx;
  207. height: 110upx;
  208. background: #fff;
  209. margin-bottom: 20upx;
  210. .tit {
  211. flex-shrink: 0;
  212. width: 120upx;
  213. font-size: $font-lg;
  214. color: $font-color-dark;
  215. }
  216. .background-img {
  217. width: 80rpx;
  218. height: 80rpx;
  219. border-radius: 50%;
  220. background: #f2f2f2;
  221. }
  222. }
  223. .row {
  224. display: flex;
  225. align-items: center;
  226. padding: 0 30upx;
  227. height: 110upx;
  228. background: #fff;
  229. button {
  230. width: 80rpx;
  231. height: 80rpx;
  232. margin: 0;
  233. padding: 0;
  234. border-radius: 50%;
  235. }
  236. .avatar {
  237. width: 80rpx;
  238. height: 80rpx;
  239. border-radius: 50%;
  240. position: relative;
  241. z-index: 2;
  242. }
  243. .tit {
  244. flex-shrink: 0;
  245. width: 120upx;
  246. font-size: $font-lg;
  247. color: $font-color-dark;
  248. }
  249. .input {
  250. flex: 1;
  251. text-align: right;
  252. font-size: $font-base;
  253. color: $color-gray;
  254. }
  255. }
  256. .add-btn {
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. margin: 158rpx auto 30rpx;
  261. width: 560rpx;
  262. height: 80rpx;
  263. background: #ff4c4c;
  264. border-radius: 40px;
  265. color: #FFFFFF;
  266. }
  267. .out {
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. margin: 0 auto 30rpx;
  272. width: 560rpx;
  273. height: 80rpx;
  274. border: 1px solid #ff4c4c;
  275. background: #FFFFFF;
  276. border-radius: 40px;
  277. color: #ff4c4c;
  278. }
  279. .psw-wrapper {
  280. width: 548rpx;
  281. height: 344rpx;
  282. background-color: #ffffff;
  283. .psw-title {
  284. width: 100%;
  285. font-size: 35rpx;
  286. padding: 43rpx 0 49rpx;
  287. text-align: center;
  288. font-weight: 800;
  289. }
  290. .psw-ipt {
  291. display: block;
  292. background-color: #dce3ed;
  293. height: 90rpx;
  294. width: 464rpx;
  295. padding-left: 30rpx;
  296. margin: 0 auto;
  297. font-size: 80rpx;
  298. }
  299. .psw-btn text {
  300. display: inline-block;
  301. text-align: center;
  302. width: 50%;
  303. padding-top: 29rpx;
  304. font-size: 35rpx;
  305. }
  306. .psw-qd {
  307. color: #32C6FF;
  308. }
  309. }
  310. </style>