userinfo.vue 6.3 KB

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