userinfo.vue 6.4 KB

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