userInfo.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="userinfo">
  3. <u-sticky>
  4. <view class="avatar-box">
  5. <view class="avatar">
  6. <Oss @upload="uploadSuccess" fliename='avatar'>
  7. <!-- <u-avatar v-if="ruleForm.avatar" size='100' :src="ruleForm.avatar" @click="avatarChange"></u-avatar>
  8. <u-icon name="camera" size='80' color='#70a7ff' v-else @click="avatarChange"></u-icon> -->
  9. <u-avatar v-if="ruleForm.avatar" size='100' :src="ruleForm.avatar"></u-avatar>
  10. <u-icon name="camera" size='80' color='#70a7ff' v-else></u-icon>
  11. </Oss>
  12. </view>
  13. </view>
  14. </u-sticky>
  15. <view class="userinfo-form">
  16. <u-form labelPosition="top" :model="ruleForm" :rules="rules" ref="form1" labelWidth='90'>
  17. <u-form-item label="用户名" borderBottom prop="username">
  18. <u-icon name="account" color='#4680F9' class="item-icon"></u-icon>
  19. <u--input readonly v-model="ruleForm.username" border="none" placeholder="用户名"></u--input>
  20. </u-form-item>
  21. <u-form-item label="手机号" borderBottom prop="phone">
  22. <u-icon name="phone" color='#4680F9' class="item-icon"></u-icon>
  23. <u--input readonly v-model="ruleForm.phone" border="none" placeholder="手机号"></u--input>
  24. </u-form-item>
  25. <u-form-item label="昵称" borderBottom prop="nickname">
  26. <u-icon name="account" color='#4680F9' class="item-icon"></u-icon>
  27. <u--input v-model="ruleForm.displayName" border="none" placeholder="昵称"></u--input>
  28. </u-form-item>
  29. <u-form-item label="姓名" borderBottom prop="name">
  30. <u-icon name="account" color='#4680F9' class="item-icon"></u-icon>
  31. <u--input v-model="ruleForm.username" border="none" placeholder="姓名"></u--input>
  32. </u-form-item>
  33. <!-- <u-form-item label="邮箱" borderBottom prop="email">
  34. <u-icon name="email" color='#4680F9' class="item-icon"></u-icon>
  35. <u--input v-model="ruleForm.email" border="none" placeholder="邮箱"></u--input>
  36. </u-form-item> -->
  37. <u-form-item label="原密码" borderBottom prop="password">
  38. <u-icon name="lock" color='#4680F9' class="item-icon"></u-icon>
  39. <u--input type='password' v-model="ruleForm.password" border="none" placeholder="原密码"></u--input>
  40. </u-form-item>
  41. <u-form-item label="新密码" borderBottom prop="newpassword1">
  42. <u-icon name="lock" color='#4680F9' class="item-icon"></u-icon>
  43. <u--input type='password' v-model="ruleForm.newpassword1" border="none" placeholder="原密码">
  44. </u--input>
  45. </u-form-item>
  46. <u-form-item label="确认密码" borderBottom prop="newpassword2">
  47. <u-icon name="lock" color='#4680F9' class="item-icon"></u-icon>
  48. <u--input type='password' v-model="ruleForm.newpassword2" border="none" placeholder="确认密码">
  49. </u--input>
  50. </u-form-item>
  51. </u-form>
  52. </view>
  53. <view class="edit-btn">
  54. <u-button type="primary" @click="submit">{{$t("base.button.confirm")}}</u-button>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. getUserInfo,
  61. editUserInfo
  62. } from "../../api/user"
  63. import {
  64. mapActions,
  65. mapMutations
  66. } from 'vuex';
  67. import {
  68. isValidateNoneMobile
  69. } from "../../utils/util";
  70. import Oss from '../../components/oss/oss'
  71. export default {
  72. data() {
  73. const validatePhone = (rule, value, callback) => {
  74. if (isValidateNoneMobile(value)[0]) {
  75. callback(new Error(isValidateNoneMobile(value)[1]));
  76. } else {
  77. callback();
  78. }
  79. };
  80. const validatePass = (rule, value, callback) => {
  81. if (this.ruleForm.password !== "") {
  82. if (value !== this.ruleForm.newpassword1) {
  83. callback(new Error("两次输入密码不一致!"));
  84. } else {
  85. callback();
  86. }
  87. } else {
  88. callback();
  89. }
  90. };
  91. return {
  92. userInfo: {},
  93. version:"",
  94. ruleForm: {
  95. username: "",
  96. password: "",
  97. newpassword1: "",
  98. newpassword2: "",
  99. avatar: "",
  100. phone: "",
  101. displayName: "",
  102. name: "",
  103. email: ""
  104. },
  105. rules: {
  106. phone: [{
  107. required: false,
  108. validator: validatePhone,
  109. trigger: "blur"
  110. }],
  111. password: [{
  112. required: true,
  113. min: 6,
  114. message: "原密码不少于6位",
  115. trigger: "blur",
  116. }, ],
  117. newpassword1: [{
  118. required: false,
  119. min: 6,
  120. message: "新密码不少于6位",
  121. trigger: "blur",
  122. }, ],
  123. newpassword2: [{
  124. required: false,
  125. validator: validatePass,
  126. trigger: "blur"
  127. }, ],
  128. },
  129. }
  130. },
  131. components: {
  132. Oss,
  133. },
  134. onLoad() {
  135. let n = 'http://tmp/eFy1HaBDvtBra84709346813f00bf69c1bccc175211c.jpg'.indexOf('/')
  136. console.log(n);
  137. this.getUserInfo()
  138. },
  139. methods: {
  140. ...mapActions({
  141. logout: 'user/logout'
  142. }),
  143. ...mapMutations({
  144. setUserInfo: 'user/login'
  145. }),
  146. uploadSuccess(data) {
  147. console.log(data, this);
  148. this.ruleForm.avatar = data.url
  149. },
  150. getUserInfo() {
  151. this.userInfo = uni.getStorageSync('userInfo')
  152. this.ruleForm.password = undefined;
  153. this.ruleForm.newpassword1 = undefined;
  154. this.ruleForm.newpassword2 = undefined;
  155. this.ruleForm.username = this.userInfo.username;
  156. this.ruleForm.phone = this.userInfo.phone;
  157. this.ruleForm.avatar = this.userInfo.avatar;
  158. this.ruleForm.displayName = this.userInfo.displayName;
  159. this.ruleForm.email = this.userInfo.email;
  160. // getUserInfo().then(res=>{
  161. // if(res.statusCode == 200){
  162. // this.userInfo = res.data.data.sysUserDTO
  163. // // this.userInfo = uni.getStorageSync('userInfo')
  164. // this.ruleForm.password = undefined;
  165. // this.ruleForm.newpassword1 = undefined;
  166. // this.ruleForm.newpassword2 = undefined;
  167. // this.ruleForm.username = this.userInfo.username;
  168. // this.ruleForm.phone = this.userInfo.phone;
  169. // this.ruleForm.avatar = this.userInfo.avatar;
  170. // this.ruleForm.nickname = this.userInfo.nickname;
  171. // this.ruleForm.name = this.userInfo.name
  172. // this.ruleForm.email = this.userInfo.email;
  173. // }
  174. // })
  175. },
  176. updataUserInfo() {
  177. getUserInfo().then(res => {
  178. if (res.statusCode === 200) {
  179. debugger
  180. this.userInfo = res.data.data.sysUser
  181. this.ruleForm.password = undefined;
  182. this.ruleForm.newpassword1 = undefined;
  183. this.ruleForm.newpassword2 = undefined;
  184. this.ruleForm.username = this.userInfo.username;
  185. this.ruleForm.phone = this.userInfo.phone;
  186. this.ruleForm.avatar = this.userInfo.avatar;
  187. this.ruleForm.nickname = this.userInfo.nickname;
  188. this.ruleForm.name = this.userInfo.name
  189. this.ruleForm.email = this.userInfo.email;
  190. uni.setStorageSync('userInfo', res.data.data.sysUser)
  191. this.setUserInfo(res.data.data.sysUser)
  192. }
  193. })
  194. },
  195. // avatarChange(){
  196. // uni.chooseImage({
  197. // count:1,
  198. // crop:{
  199. // width:375,
  200. // height:375
  201. // },
  202. // success:(res)=>{
  203. // this.uploadFilePromise(res.tempFilePaths[0]).then(res=>{
  204. // if(res.statusCode == 200){
  205. // this.ruleForm.avatar = res.data.data.url
  206. // }else{
  207. // uni.showToast({
  208. // title: res.data.msg,
  209. // icon: 'none',
  210. // duration: 2000
  211. // })
  212. // }
  213. // })
  214. // }
  215. // })
  216. // },
  217. // uploadFilePromise(url,) {
  218. // return new Promise((resolve, reject) => {
  219. // let a = uni.uploadFile({
  220. // url: '/admin/sys-file/upload',
  221. // filePath: url,
  222. // name: 'file',
  223. // header:{
  224. // 'Authorization': 'Bearer ' + uni.getStorageSync('token'),
  225. // },
  226. // success: (res) => {
  227. // res.data=JSON.parse(res.data)
  228. // setTimeout(() => {
  229. // resolve(res)
  230. // }, 1000)
  231. // }
  232. // });
  233. // })
  234. // },
  235. submit() {
  236. let _this = this
  237. this.$refs.form1.validate().then(res => {
  238. editUserInfo(this.ruleForm).then(res => {
  239. if (res.statusCode == 200 && res.data.code == 0) {
  240. uni.$u.toast(_this.$t("userinfo.setSucceeded"))
  241. this.updataUserInfo()
  242. }else{
  243. uni.$u.toast(res.data.msg)
  244. }
  245. })
  246. }).catch(errors => {
  247. console.log(errors);
  248. uni.$u.toast(errors[0].message)
  249. })
  250. },
  251. },
  252. }
  253. </script>
  254. <style lang="less" scoped>
  255. .userinfo {
  256. // padding: 32rpx;
  257. .avatar-box {
  258. position: relative;
  259. background-color: #4680F9;
  260. height: 100rpx;
  261. border-bottom-right-radius: 80rpx;
  262. border-bottom-left-radius: 80rpx;
  263. margin-bottom: 140rpx;
  264. .avatar {
  265. position: absolute;
  266. width: 160rpx;
  267. height: 160rpx;
  268. border: 2px solid #4680F9;
  269. bottom: -80rpx;
  270. left: calc(50% - 80rpx);
  271. border-radius: 50%;
  272. background-color: #fff;
  273. display: flex;
  274. justify-content: center;
  275. align-items: center;
  276. }
  277. }
  278. .avatar-wrap {
  279. margin: auto;
  280. }
  281. .userinfo-form {
  282. padding: 0 64rpx 150rpx;
  283. .item-icon {
  284. margin-right: 20rpx;
  285. }
  286. }
  287. .edit-btn {
  288. position: fixed;
  289. bottom: 0;
  290. // height: 150rpx;
  291. padding: 24rpx 64rpx;
  292. width: calc(100% - 128rpx);
  293. background-color: #fff;
  294. border-top-right-radius: 60rpx;
  295. border-top-left-radius: 60rpx;
  296. z-index: 2000;
  297. }
  298. }
  299. .bottom-back {
  300. margin-top: 10px;
  301. width: 750rpx;
  302. height: 44px;
  303. /* #ifndef APP-NVUE */
  304. display: flex;
  305. /* #endif */
  306. flex-direction: column;
  307. justify-content: center;
  308. align-items: center;
  309. /* #ifndef APP-NVUE */
  310. border: none;
  311. /* #endif */
  312. border-width: 0;
  313. border-radius: 0;
  314. background-color: #FFFFFF;
  315. }
  316. .bottom-back-text {
  317. font-size: 33rpx;
  318. }
  319. /deep/ .u-form-item {
  320. margin-bottom: 24rpx;
  321. }
  322. /deep/ .u-button--primary {
  323. color: #fff;
  324. background-color: #4680F9;
  325. border-color: #4680F9;
  326. border-width: 1px;
  327. border-style: solid;
  328. border-radius: 20rpx;
  329. }
  330. /deep/ .u-form-item__body__right__content {
  331. flex-direction: row;
  332. }
  333. </style>