userinfo.vue 6.7 KB

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