userCenter.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="user-center">
  3. <u-popup :show="show" :customStyle="popupStyle" bgColor="#F7F7F7" :overlay="false" zIndex="9998" mode="left"
  4. @close="onClose">
  5. <view :style="{ 'height': spaceUsage }" />
  6. <view class="head-p">
  7. 账号信息
  8. <text class="cuIcon-close" @click="onClose" />
  9. </view>
  10. <upload maxCount="1" @uploadCallback="uploadCallback">
  11. <navigator class="portrait-p-box" url="#">
  12. <view class="label">
  13. 头像
  14. </view>
  15. <view class="content">
  16. <image class="profile-photo" v-if="userMsg.attinfos.length" :src="userMsg.attinfos[0].url"
  17. mode="aspectFill" />
  18. <view v-else class="profile-photo">
  19. <view class="substitution">
  20. <text class="iconfont icon-wode-xuanzhong" />
  21. </view>
  22. </view>
  23. <text class="iconfont icon-a-wodetiaozhuan" />
  24. </view>
  25. </navigator>
  26. </upload>
  27. <view class="rests-p-box">
  28. <view class="row">
  29. <view class="label">
  30. 工号
  31. </view>
  32. <view class="content">
  33. {{ userMsg.accountno }}
  34. </view>
  35. </view>
  36. <navigator url="#" class="row" @click="openModal('name', '姓名', userMsg.name, '请填写姓名')">
  37. <view class="label">
  38. 姓名
  39. </view>
  40. <view class="content">
  41. {{ userMsg.name || '--' }}
  42. <text class="iconfont icon-a-wodetiaozhuan" />
  43. </view>
  44. </navigator>
  45. <navigator url="#" class="row" @click="openModal('phonenumber', '手机号', userMsg.phonenumber, '请填写手机号码')">
  46. <view class="label">
  47. 手机号
  48. </view>
  49. <view class="content">
  50. {{ userMsg.phonenumber || '--' }}
  51. <text class="iconfont icon-a-wodetiaozhuan" />
  52. </view>
  53. </navigator>
  54. <block v-if="userMsg.hr.userid">
  55. <navigator url="#" class="row" @click="openModal('email', '邮箱', userMsg.hr.email, '请填写邮箱')">
  56. <view class="label">
  57. 邮箱
  58. </view>
  59. <view class="content">
  60. {{ userMsg.hr.email || '--' }}
  61. <text class="iconfont icon-a-wodetiaozhuan" />
  62. </view>
  63. </navigator>
  64. <view class="row">
  65. <view class="label">
  66. 部门
  67. </view>
  68. <view class="content">
  69. {{ userMsg.hr.depname || '--' }}
  70. </view>
  71. </view>
  72. <view class="row">
  73. <view class="label">
  74. 职位
  75. </view>
  76. <view class="content">
  77. {{ userMsg.hr.position || '--' }}
  78. </view>
  79. </view>
  80. </block>
  81. </view>
  82. </u-popup>
  83. <u-overlay :show="show" zIndex="9997" @click="onClose" />
  84. <u-modal :show="changeUser.showModal" @confirm="changeUserMsg" @cancel="onCancel" showCancelButton ref="uModal"
  85. :asyncClose="true">
  86. <view class="modal-content">
  87. <view class="title">
  88. 修改{{ changeUser.title }}
  89. </view>
  90. <view style="margin-top: 20px;" />
  91. <u-input :focus="inputFocus" :placeholder="changeUser.placeholder" border="surround"
  92. v-model="changeUser.changeValue" :type="changeUser.name == 'phonenumber' ? 'number' : 'text'" />
  93. <block v-if="changeUser.name == 'phonenumber'">
  94. <view style="margin-top: 10px;" />
  95. <u-input :focus="passwordFocus" placeholder="短信验证码" border="surround" v-model="password" type="number">
  96. <template slot="suffix">
  97. <u-button @tap="getCode" type="success" size="mini">{{ tips }} </u-button>
  98. </template>
  99. </u-input>
  100. </block>
  101. </view>
  102. </u-modal>
  103. </view>
  104. </template>
  105. <script>
  106. import {
  107. queryStr,
  108. CheckEmail,
  109. CheckPhoneNumber
  110. } from "../../../utils/basicInspection";
  111. import upload from "../../../components/my-upload.vue";
  112. import { hexMD5 } from "../../login/modules/md5";
  113. let count = 30,
  114. countDown = null;
  115. export default {
  116. props: {
  117. userMsg: {
  118. type: Object
  119. },
  120. getMsg: {
  121. type: Function
  122. }
  123. },
  124. components: { upload },
  125. data() {
  126. return {
  127. show: false,
  128. inputFocus: false,
  129. passwordFocus: false,
  130. spaceUsage: 0,
  131. popupStyle: {
  132. width: "88.000vw",
  133. background: "#F7F7F7",
  134. padding: "2.667vw",
  135. boxSizing: "border-box"
  136. },
  137. changeUser: {
  138. name: "",
  139. showModal: false,
  140. title: "",
  141. changeValue: "",
  142. placeholder: "",
  143. },
  144. password: "",
  145. tips: "获取验证码"
  146. }
  147. },
  148. methods: {
  149. /* 关闭用户中心 */
  150. onClose() {
  151. this.show = false;
  152. },
  153. /* 开始修改 */
  154. openModal(name, title, value, placeholder) {
  155. this.changeUser = {
  156. name,
  157. showModal: true,
  158. title,
  159. changeValue: "",
  160. placeholder: value || placeholder,
  161. }
  162. console.log(this.changeUser)
  163. setTimeout(() => {
  164. this.inputFocus = true
  165. }, 100)
  166. },
  167. /* 取消修改 */
  168. onCancel() {
  169. this.changeUser.showModal = false
  170. this.inputFocus = false
  171. },
  172. /* 修改用户信息 */
  173. changeUserMsg() {
  174. let changeUser = this.changeUser,
  175. content = {
  176. name: this.userMsg.name,
  177. email: this.userMsg.hr.email || "",
  178. phonenumber: this.userMsg.phonenumber
  179. };
  180. if (["name", 'phonenumber'].some(v => v == changeUser.name) && changeUser.changeValue == '') {
  181. uni.showToast({
  182. title: changeUser.title + '不可为空', icon: "none"
  183. })
  184. return this.$refs.uModal.loading = false;
  185. }
  186. if (changeUser.name == 'name') {
  187. content.name = queryStr(changeUser.changeValue, '已移除非法字符');
  188. } else if (changeUser.name == 'email') {
  189. if (!CheckEmail(changeUser.changeValue.trim())) return this.$refs.uModal.loading = false;
  190. content.email = changeUser.changeValue.trim();
  191. } else if (changeUser.name == 'phonenumber') {
  192. if (!CheckPhoneNumber(changeUser.changeValue.trim())) {
  193. uni.showToast({
  194. title: "请检查手机号",
  195. icon: "none"
  196. })
  197. return this.$refs.uModal.loading = false;
  198. }
  199. if (this.password == "") {
  200. uni.showToast({
  201. title: "还未输入验证码",
  202. icon: "none"
  203. })
  204. return this.$refs.uModal.loading = false;
  205. }
  206. content.phonenumber = changeUser.changeValue.trim();
  207. content.password = hexMD5(this.password);
  208. }
  209. this.$Http.basic({
  210. id: 20230608105602,
  211. content
  212. }).then(res => {
  213. console.log("修改用户信息", res)
  214. if (this.cutoff(res.msg, changeUser.title + '修改成功')) return this.$refs.uModal.loading = false;
  215. this.password = ""
  216. clearInterval(countDown);
  217. this.tips = '获取验证码';
  218. count = 30;
  219. this.userMsg.name = content.name;
  220. this.userMsg.hr.email && (this.userMsg.hr.email = content.email);
  221. this.onCancel();
  222. this.$emit("getMsg")
  223. })
  224. },
  225. /* 更新用户头像 */
  226. uploadCallback(attachmentids) {
  227. let attinfos = [];
  228. // uni.get
  229. //删除原本头像
  230. if (this.userMsg.attinfos.length) this.$Http.basic({
  231. "classname": "system.attachment.Attachment",
  232. "method": "deleteFileLink",
  233. "content": {
  234. "linksids": this.userMsg.attinfos.map(v => v.linksid)
  235. }
  236. }).then(res => {
  237. console.log("删除原本头像", res)
  238. if (this.cutoff(res.msg)) return;
  239. this.userMsg.attinfos = attinfos;
  240. })
  241. //绑定新头像
  242. if (attachmentids) this.$Http.basic({
  243. "classname": "system.attachment.Attachment",
  244. "method": "createFileLink",
  245. "content": {
  246. "ownertable": "sys_users",
  247. "ownerid": uni.getStorageSync('userMsg').userid,
  248. "usetype": "headportrait",
  249. "attachmentids": attachmentids
  250. }
  251. }).then(res => {
  252. console.log("绑定头像", res)
  253. if (this.cutoff(res.msg)) return;
  254. this.$emit("getMsg");
  255. uni.showToast({
  256. title: "头像修改成功",
  257. icon: "none"
  258. })
  259. })
  260. },
  261. async getCode() {
  262. let phonenumber = this.changeUser.changeValue,
  263. title = "";
  264. if (phonenumber == "") {
  265. title = '手机号码不可为空'
  266. } else if (!CheckPhoneNumber(phonenumber.trim())) {
  267. title = '请检查手机号码'
  268. } else {
  269. if (this.tips == '获取验证码' || this.tips == '重新获取') {
  270. let res = await this.$Http.basic({
  271. id: 20230608105502,
  272. "content": {
  273. phonenumber
  274. }
  275. });
  276. console.log("获取短信验证码", res)
  277. uni.showToast({
  278. title: res.msg,
  279. icon: "none"
  280. })
  281. if (res.data == '失败') return;
  282. count -= 1;
  283. this.tips = count + 's后可重新获取';
  284. countDown = setInterval(() => {
  285. if (count == 0) {
  286. clearInterval(countDown);
  287. this.tips = '重新获取';
  288. count = 30;
  289. } else {
  290. count -= 1;
  291. this.tips = count + 's后可重新获取';
  292. }
  293. }, 1000)
  294. } else {
  295. title = `${count}秒后可重新获取`
  296. }
  297. };
  298. if (title) uni.showToast({
  299. title,
  300. icon: "none"
  301. })
  302. }
  303. },
  304. }
  305. </script>
  306. <style lang="scss" scoped>
  307. .user-center {
  308. .head-p {
  309. width: 100%;
  310. display: flex;
  311. justify-content: space-between;
  312. height: 21px;
  313. font-size: 15px;
  314. color: #333333;
  315. line-height: 21px;
  316. .cuIcon-close {
  317. padding-left: 10px;
  318. }
  319. }
  320. .portrait-p-box,
  321. .rests-p-box {
  322. width: 310px;
  323. background: #FFFFFF;
  324. box-sizing: border-box;
  325. padding-right: 10px;
  326. border-radius: 4px;
  327. overflow: hidden;
  328. }
  329. .portrait-p-box {
  330. height: 60px;
  331. margin-top: 15px;
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-between;
  335. .label {
  336. font-size: 14px;
  337. font-family: PingFang SC-Regular, PingFang SC;
  338. color: #666666;
  339. margin-left: 15px;
  340. }
  341. .content {
  342. display: flex;
  343. align-items: center;
  344. .icon-a-wodetiaozhuan {
  345. font-size: 18px;
  346. color: #999;
  347. }
  348. .profile-photo {
  349. width: 32px;
  350. height: 32px;
  351. border-radius: 50%;
  352. overflow: hidden;
  353. .substitution {
  354. width: 32px;
  355. line-height: 32px;
  356. text-align: center;
  357. background: #EFF4FA;
  358. .iconfont {
  359. font-size: 16px;
  360. color: #7C98BB;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. .rests-p-box {
  367. margin-top: 10px;
  368. .row {
  369. display: flex;
  370. width: 310px;
  371. box-sizing: border-box;
  372. padding: 13px 10px 12px 15px;
  373. .label {
  374. min-width: 28px;
  375. flex: 1;
  376. font-size: 14px;
  377. line-height: 20px;
  378. }
  379. .content {
  380. line-height: 20px;
  381. font-size: 14px;
  382. color: #333333;
  383. .icon-a-wodetiaozhuan {
  384. font-size: 14px;
  385. }
  386. }
  387. }
  388. }
  389. .modal-content {
  390. width: 100%;
  391. .title {
  392. width: 100%;
  393. text-align: center;
  394. font-size: 18px;
  395. color: #333;
  396. }
  397. .input {
  398. width: 100%;
  399. margin-top: 22px;
  400. border: 1px solid #888;
  401. height: 30px;
  402. line-height: 30px;
  403. padding-left: 6px;
  404. font-size: 14px;
  405. border-radius: 4px;
  406. }
  407. }
  408. /deep/ .uni-input-placeholder,
  409. /deep/.uni-input-wrapper {
  410. font-size: 12px;
  411. }
  412. /deep/ .u-button__text {
  413. font-size: 10px !important;
  414. }
  415. }
  416. </style>