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 :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. userEdit({
  119. avatar: this.userInfo.avatar,
  120. nickname: this.userInfo.nickname
  121. })
  122. .then(e => {
  123. this.$api.msg('修改成功');
  124. setTimeout(() => {
  125. uni.switchTab({
  126. url: '/pages/user/user'
  127. });
  128. }, 1000);
  129. console.log(e);
  130. })
  131. .catch(e => {
  132. console.log(e);
  133. });
  134. },
  135. toLogout() {
  136. let obj = this;
  137. uni.showModal({
  138. content: '确定要退出登录么',
  139. success: (e) => {
  140. if (e.confirm) {
  141. logout({}).then((e) => {
  142. uni.navigateBack();
  143. }).catch((e) => {
  144. console.log(e);
  145. })
  146. obj.logout();
  147. }
  148. }
  149. });
  150. },
  151. test(e) {
  152. console.log(e.detail, '123456');
  153. },
  154. onChooseAvatar(e) {
  155. // console.log(e.detail.avatarUrl);
  156. this.uploadImage(e.detail.avatarUrl)
  157. // this.userInfo.avatar = e.detail.avatarUrl;
  158. },
  159. cancel() {
  160. // this.$refs.popup.open();
  161. let obj = this;
  162. uni.showModal({
  163. content: '确定要退出登录么',
  164. success: e => {
  165. if (e.confirm) {
  166. logout({}).then(e => {
  167. obj.logout();
  168. uni.switchTab({
  169. url: '/pages/index/index'
  170. })
  171. })
  172. .catch(e => {
  173. console.log(e);
  174. });
  175. }
  176. }
  177. });
  178. },
  179. qx() {
  180. this.password = '';
  181. this.$refs.popup.close();
  182. },
  183. pswQd() {
  184. if (this.password != this.userInfo.phone) {
  185. this.$refs.popup.close();
  186. this.password = '';
  187. this.$api.msg("请输入自己的账户")
  188. return
  189. }
  190. this.$refs.popup.close();
  191. this.password = '';
  192. this.$api.msg("申请注销成功,请耐心等待审核")
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. .row1 {
  199. display: flex;
  200. align-items: center;
  201. justify-content: space-between;
  202. position: relative;
  203. padding: 0 30upx;
  204. height: 110upx;
  205. background: #fff;
  206. margin-bottom: 20upx;
  207. .tit {
  208. flex-shrink: 0;
  209. width: 120upx;
  210. font-size: $font-lg;
  211. color: $font-color-dark;
  212. }
  213. .background-img {
  214. width: 80rpx;
  215. height: 80rpx;
  216. border-radius: 50%;
  217. background: #f2f2f2;
  218. }
  219. }
  220. .row {
  221. display: flex;
  222. align-items: center;
  223. padding: 0 30upx;
  224. height: 110upx;
  225. background: #fff;
  226. button {
  227. width: 80rpx;
  228. height: 80rpx;
  229. margin: 0;
  230. padding: 0;
  231. border-radius: 50%;
  232. }
  233. .avatar {
  234. width: 80rpx;
  235. height: 80rpx;
  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>