userInfo.vue 9.7 KB

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