phone.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <!--
  2. * @Author: wangwei
  3. * @Date: 2020-12-29 16:05:36
  4. * @LastEditTime: 2021-01-15 16:33:06
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 手机号管理
  7. * @FilePath: /java-pc/src/views/member/center/accountSafe.vue
  8. -->
  9. <template>
  10. <div class="sld_phone_mange">
  11. <MemberTitle :memberTitle="L['手机号管理']"></MemberTitle>
  12. <div class="container">
  13. <div class="title">{{ L["手机号管理"] }}</div>
  14. <div class="mange_con">
  15. <span class="current"
  16. >{{ L["当前手机号"] }} {{ memberInfo.data.memberMobile == null ? ':未设置' : ':'+memberInfo.data.memberMobile }}</span
  17. >
  18. <div v-if="step == 1" class="sms_code_con flex_row_center_center">
  19. <el-input
  20. v-model="old_sms_code"
  21. :placeholder="L['请输入短信验证码']"
  22. type="number"
  23. ></el-input>
  24. <div class="get_sms pointer" @click="getSmsCode">
  25. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  26. </div>
  27. </div>
  28. <el-input
  29. v-if="step == 2"
  30. class="password input"
  31. v-model="new_mobile"
  32. :placeholder="L['请输入新手机号']"
  33. type="number"
  34. >
  35. </el-input>
  36. <div
  37. v-if="step == 2"
  38. class="sms_code_con flex_row_center_center margin"
  39. >
  40. <el-input
  41. v-model="new_sms_code"
  42. :placeholder="L['请输入短信验证码']"
  43. type="number"
  44. ></el-input>
  45. <div class="get_sms pointer" @click="getSmsCode">
  46. {{ countDownM ? countDownM + L["s后获取"] : L["获取验证码"] }}
  47. </div>
  48. </div>
  49. <div class="error_tip">
  50. <span
  51. v-if="errorMsg"
  52. style="color: #e1251b; font-size: 14px"
  53. class="iconfont icon-jubao"
  54. ></span>
  55. {{ errorMsg }}
  56. </div>
  57. <div class="next flex_row_center_center" @click="next">
  58. {{ step == 1 ? L["下一步"] : L["确定"] }}
  59. </div>
  60. </div>
  61. <div class="manage_tips">
  62. <p class="tips_title">{{ L["温馨提示"] }}:</p>
  63. <p>• {{ L["为了保障您的账号安全,变更重要信息需进行身份验证。"] }}</p>
  64. <p>• {{ L["变更过程中有任何疑问请联系在线客服解决。"] }}</p>
  65. <p>
  66. {{ L["如手机号/邮箱已不再使用无法获取验证码,请联系在线客服解决。"] }}
  67. </p>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <script setup>
  73. import { ElInput, ElMessage, ElMessageBox } from "element-plus";
  74. import { getCurrentInstance, reactive, ref, watch } from "vue";
  75. // import { lang_zn } from "@/assets/language/zh";
  76. import { getCurLanguage } from '@/composables/common.js';
  77. import { useFiltersStore } from "@/store/filter.js";
  78. const filtersStore = useFiltersStore();
  79. // const L = lang_zn;
  80. const L = getCurLanguage();
  81. definePageMeta({
  82. layout: "member",
  83. middleware: ["auth"],
  84. });
  85. const { proxy } = getCurrentInstance();
  86. const errorMsg = ref("");
  87. const step = ref(1);
  88. const old_sms_code = ref("");
  89. const new_sms_code = ref("");
  90. const new_mobile = ref("");
  91. const timeOutId = ref(""); //定时器的返回值
  92. const countDownM = ref(0); //短信验证码倒计时
  93. const memberInfo = reactive({ data: filtersStore.getMemberInfo });
  94. const preventFre = ref(false);
  95. if(memberInfo.data.memberMobile == null){
  96. step.value = 2
  97. }
  98. const getSmsCode = () => {
  99. if (preventFre.value) {
  100. return false;
  101. }
  102. preventFre.value = true;
  103. if (step.value == 2) {
  104. //手机号验证
  105. if (!new_mobile.value) {
  106. preventFre.value = false;
  107. errorMsg.value = L["请输入手机号"];
  108. return false;
  109. } else {
  110. let checkMobileVal = checkPhone(new_mobile.value);
  111. if (checkMobileVal !== true) {
  112. errorMsg.value = checkMobileVal;
  113. preventFre.value = false;
  114. return false;
  115. }
  116. }
  117. }
  118. if (countDownM.value) {
  119. return false;
  120. }
  121. var param = {};
  122. param.verifyType = 2;
  123. param.changeType = step.value == 1 ? "old" : "new";
  124. param.verifyAddr =
  125. step.value == 1 ? memberInfo.data.memberMobile : new_mobile.value;
  126. get("v3/msg/front/commons/sendVerifyCode", param).then((res) => {
  127. if (res.state == 200) {
  128. errorMsg.value = "";
  129. countDownM.value = 60;
  130. countDown();
  131. } else {
  132. preventFre.value = false;
  133. ElMessage.error(res.msg);
  134. }
  135. });
  136. };
  137. const next = () => {
  138. preventFre.value = false;
  139. if (step.value == 1) {
  140. //验证码校验
  141. if (!old_sms_code.value) {
  142. errorMsg.value = L["请输入短信验证码"];
  143. return false;
  144. } else {
  145. let checkSmsCodeVal = checkSmsCode(old_sms_code.value);
  146. if (checkSmsCodeVal !== true) {
  147. errorMsg.value = checkSmsCodeVal;
  148. return false;
  149. }
  150. }
  151. post("v3/member/front/memberPassword/verifyOldMobile", {
  152. memberMobile: memberInfo.data.memberMobile,
  153. smsCode: old_sms_code.value,
  154. })
  155. .then((res) => {
  156. if (res.state == 200) {
  157. step.value = 2;
  158. clearTimeout(timeOutId.value);
  159. countDownM.value = 0;
  160. errorMsg.value = "";
  161. } else {
  162. errorMsg.value = res.msg;
  163. }
  164. });
  165. } else if (step.value == 2) {
  166. //验证码校验
  167. if (!new_sms_code.value) {
  168. errorMsg.value = L["请输入短信验证码"];
  169. return false;
  170. } else {
  171. let checkSmsCodeVal = checkSmsCode(new_sms_code.value);
  172. if (checkSmsCodeVal !== true) {
  173. errorMsg.value = checkSmsCodeVal;
  174. return false;
  175. }
  176. }
  177. post("v3/member/front/memberPassword/editMobile", {
  178. memberMobile: new_mobile.value,
  179. smsCode: new_sms_code.value,
  180. })
  181. .then((res) => {
  182. if (res.state == 200) {
  183. clearTimeout(timeOutId.value);
  184. //更新个人信息
  185. memberInfo.data.memberMobile = new_mobile.value;
  186. // store.commit("updateMemberInfo", memberInfo.data);
  187. filtersStore.setMemberInfo(memberInfo.data)
  188. countDownM.value = 0;
  189. ElMessage.success(res.msg);
  190. step.value = 1;
  191. old_sms_code.value = "";
  192. errorMsg.value = "";
  193. } else if (res.state == 267) {
  194. ElMessageBox.confirm(res.msg, L["提示"], {
  195. confirmButtonText: L["确定"],
  196. cancelButtonText: L["取消"],
  197. type: "warning",
  198. }).then(() => {
  199. post("v3/member/front/memberPassword/editMobile", {
  200. memberMobile: new_mobile.value,
  201. smsCode: new_sms_code.value,
  202. isUnbound: 1,
  203. })
  204. .then((res) => {
  205. if (res.state == 200) {
  206. //更新个人信息
  207. memberInfo.data.memberMobile = new_mobile.value;
  208. // store.commit("updateMemberInfo", memberInfo.data);
  209. filtersStore.setMemberInfo(memberInfo.data)
  210. ElMessage.success(res.msg);
  211. step.value = 1;
  212. old_sms_code.value = "";
  213. } else {
  214. ElMessage.error(res.msg);
  215. }
  216. });
  217. });
  218. } else {
  219. errorMsg.value = res.msg;
  220. }
  221. });
  222. }
  223. };
  224. //倒计时
  225. const countDown = () => {
  226. countDownM.value--;
  227. if (countDownM.value == 0) {
  228. preventFre.value = false;
  229. clearTimeout(timeOutId.value);
  230. } else {
  231. timeOutId.value = setTimeout(countDown, 1000);
  232. }
  233. };
  234. watch([old_sms_code, new_sms_code, new_mobile], () => {
  235. old_sms_code.value = old_sms_code.value.substring(0, 6);
  236. new_sms_code.value = new_sms_code.value.substring(0, 6);
  237. new_mobile.value = new_mobile.value.substring(0, 11);
  238. errorMsg.value = "";
  239. });
  240. </script>
  241. <style lang="scss" scoped>
  242. .sld_phone_mange {
  243. width: 1007px;
  244. float: left;
  245. margin-left: 10px;
  246. .container {
  247. background-color: white;
  248. width: 100%;
  249. box-sizing: border-box;
  250. border: 1px solid #eaeaea;
  251. padding: 25px 40px;
  252. .title {
  253. font-size: 18px;
  254. border-bottom: 1px dashed #eaeaea;
  255. padding-bottom: 25px;
  256. font-weight: 600;
  257. margin-bottom: 20px;
  258. }
  259. .mange_con {
  260. width: 360px;
  261. margin: 62px auto 0;
  262. .current {
  263. line-height: 56px;
  264. font-size: 14px;
  265. color: #333333;
  266. width: 100%;
  267. text-align: center;
  268. display: block;
  269. }
  270. .error_tip {
  271. height: 15px;
  272. margin-top: 10px;
  273. color: #f30213;
  274. i {
  275. margin-right: 10px;
  276. }
  277. }
  278. .sms_code_con {
  279. width: 100%;
  280. .get_sms {
  281. width: 100px;
  282. height: 40px;
  283. line-height: 38px;
  284. background: #00985e;
  285. text-align: center;
  286. color: white;
  287. font-size: 14px;
  288. border-radius: 0 3px 3px 0;
  289. }
  290. }
  291. .margin {
  292. margin-top: 20px;
  293. }
  294. .next {
  295. width: 170px;
  296. height: 40px;
  297. background: #00985e;
  298. color: #fff;
  299. font-size: 18px;
  300. font-weight: bold;
  301. text-align: center;
  302. color: white;
  303. margin-top: 20px;
  304. line-height: 40px;
  305. border-radius: 3px;
  306. margin: 42px auto 0;
  307. cursor: pointer;
  308. }
  309. }
  310. .manage_tips {
  311. width: 938px;
  312. background: #fffdee;
  313. border: 1px solid #edd28b;
  314. padding: 15px 36px;
  315. margin-top: 117px;
  316. p {
  317. color: #555555;
  318. margin-top: 10px;
  319. }
  320. .tips_title {
  321. font-weight: bold;
  322. margin-bottom: 11px;
  323. margin-top: 0;
  324. }
  325. }
  326. }
  327. }
  328. </style>
  329. <style lang="scss">
  330. .sld_phone_mange {
  331. .el-input {
  332. width: 280px;
  333. height: 40px;
  334. border-radius: 3px 0 0 3px;
  335. position: inherit;
  336. }
  337. .el-input__inner {
  338. width: 280px;
  339. height: 40px;
  340. border-radius: 3px 0 0 3px;
  341. }
  342. .input {
  343. width: 100%;
  344. height: 40px;
  345. margin-top: 20px;
  346. border-radius: 3px;
  347. .el-input__wrapper{
  348. display: block;
  349. }
  350. .el-input__inner {
  351. height: 40px;
  352. border-radius: 3px;
  353. width: 100%;
  354. }
  355. }
  356. }
  357. input[type="number"] {
  358. -moz-appearance: textfield;
  359. }
  360. input[type="number"]::-webkit-inner-spin-button,
  361. input[type="number"]::-webkit-outer-spin-button {
  362. -webkit-appearance: none;
  363. margin: 0;
  364. }
  365. /**
  366. * 解决el-input设置类型为number时,中文输入法光标上移问题
  367. **/
  368. .el-input__inner {
  369. line-height: 1px !important;
  370. }
  371. </style>