SecurityCenterTab.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="user-form crm-form">
  3. <uni-row class="demo-uni-row uni-row1" :gutter="20">
  4. <uni-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" >
  5. <view class="card bg-body p-3">
  6. <view class="content-title">
  7. <view v-t="'PersonalManagement.Title.CustomerZonePasswordChange'"></view>
  8. </view>
  9. <hr>
  10. <uni-forms :model="passwordInfo" labelWidth="200" label-position="top">
  11. <uni-row class="demo-uni-row">
  12. <uni-col :xs="24">
  13. <uni-forms-item :label="t('PersonalManagement.Label.OldPassword')">
  14. <uni-easyinput :clearable="false" v-model="passwordInfo.oldPassword"
  15. :placeholder="locale == 'es' ? 'Introduzca el nombre de la red' : t('placeholder.input')" />
  16. </uni-forms-item>
  17. </uni-col>
  18. <uni-col :xs="24">
  19. <uni-forms-item :label="t('PersonalManagement.Label.NewPassword')">
  20. <uni-easyinput :clearable="false" v-model="passwordInfo.newPassword"
  21. :placeholder="locale == 'es' ? 'Introduzca nueva contraseña' : t('placeholder.input')" />
  22. </uni-forms-item>
  23. </uni-col>
  24. <uni-col :xs="24">
  25. <uni-forms-item :label="t('PersonalManagement.Label.NewPasswordConfirmation')">
  26. <uni-easyinput :clearable="false" v-model="passwordInfo.checkPass"
  27. :placeholder="locale == 'es' ? 'Introduzca nueva contraseña' : t('placeholder.input')" />
  28. </uni-forms-item>
  29. </uni-col>
  30. <uni-col :xs="24">
  31. <view class="notice-list">
  32. <view v-for="(item, index) in noticeItems" :key="index"
  33. :class="['notice-item', item.valid ? 'isOK' : '']">
  34. {{ item.label }}
  35. </view>
  36. </view>
  37. </uni-col>
  38. <uni-col :xs="24">
  39. <view class="btn btn-confirm mt-4" @click="passwordUpdate">{{ locale == 'es' ?
  40. 'Actualizarcontraseña' : t('Btn.Application') }}</view>
  41. </uni-col>
  42. </uni-row>
  43. </uni-forms>
  44. </view>
  45. </uni-col>
  46. <uni-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
  47. <view class="card bg-body p-3">
  48. <view class="content-title">
  49. <view v-t="'PersonalManagement.Title.EmailChange'"></view>
  50. </view>
  51. <hr>
  52. <uni-forms :model="emailInfo" labelWidth="200" label-position="top">
  53. <uni-row class="demo-uni-row">
  54. <uni-col :xs="24">
  55. <uni-forms-item :label="t('PersonalManagement.Label.OldEmail')">
  56. <uni-easyinput :clearable="false" v-model="emailInfo.oldEmail"
  57. :placeholder="t('placeholder.input')" />
  58. </uni-forms-item>
  59. </uni-col>
  60. <uni-col :xs="24">
  61. <uni-forms-item :label="t('PersonalManagement.Label.NewEmail')">
  62. <uni-easyinput :clearable="false" v-model="emailInfo.email"
  63. :placeholder="t('placeholder.input')" />
  64. </uni-forms-item>
  65. </uni-col>
  66. <uni-col :xs="24">
  67. <view class="email-code">
  68. <uni-forms-item :label="t('PersonalManagement.Label.MailboxVerificationCode')"
  69. class="email-code-item">
  70. <uni-easyinput :clearable="false" v-model="emailInfo.emailCode"
  71. :placeholder="locale == 'es' ? 'Código de 6 dígitos' : t('placeholder.input')" />
  72. </uni-forms-item>
  73. <view class="btn btn-code" @click="handleGetCode">{{ getCodeString }}</view>
  74. </view>
  75. </uni-col>
  76. <uni-col :xs="24">
  77. <view class="btn btn-confirm mt-4" @click="emailUpdate">{{ locale == 'es' ?
  78. 'Actualizarcontraseña' : t('Btn.Application') }}</view>
  79. </uni-col>
  80. </uni-row>
  81. </uni-forms>
  82. </view>
  83. </uni-col>
  84. </uni-row>
  85. </view>
  86. </template>
  87. <script setup lang="ts">
  88. import { computed, ref, onMounted } from 'vue';
  89. import { useI18n } from 'vue-i18n';
  90. import { showToast } from "@/utils/toast";
  91. import { personalApi } from '@/service/personal';
  92. import { useEmailCountdown } from '@/hooks/useEmailCountdown';
  93. import config from '@/config';
  94. const {
  95. time,
  96. text: getCodeString,
  97. canSend,
  98. start,
  99. restore,
  100. clear,
  101. } = useEmailCountdown()
  102. const { t, locale } = useI18n();
  103. interface BankListType {
  104. key: string;
  105. label: string;
  106. icon: string;
  107. }
  108. const passwordInfo = ref({
  109. oldPassword: '',
  110. newPassword: '',
  111. checkPass: ''
  112. });
  113. const emailInfo = ref({
  114. email: '',
  115. });
  116. const rule1 = computed(() => {
  117. if (!passwordInfo.value.newPassword) {
  118. return false;
  119. }
  120. return /^.{8,16}$/.test(passwordInfo.value.newPassword);
  121. });
  122. const rule2 = computed(() => {
  123. return /^(?=.*?[a-z])(?=.*?[A-Z]).*$/.test(passwordInfo.value.newPassword);
  124. });
  125. const rule3 = computed(() => {
  126. return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?!.*([~!@&%$^\\(\\)#_]).*\\1.*\\1)[A-Za-z0-9~!@&%$^\\(\\)#_]{8,16}$/.test(
  127. passwordInfo.value.newPassword
  128. );
  129. });
  130. const rule4 = computed(() => {
  131. console.log(/^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@&%$^*./\\(\\)\\+\\=#_-])[A-Za-z0-9~!@&%$^*./\\(\\)\\+\\=#_-]{8,16}$/.test(passwordInfo.value.newPassword))
  132. return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@&%$^*./\\(\\)\\+\\=#_-])[A-Za-z0-9~!@&%$^*./\\(\\)\\+\\=#_-]{8,16}$/.test(
  133. passwordInfo.value.newPassword
  134. );
  135. });
  136. const noticeItems = computed(() => [
  137. { label: t('signup.form.rules.1st'), valid: rule1.value },
  138. { label: t('signup.form.rules.2nd'), valid: rule2.value },
  139. { label: t('signup.form.rules.4rd'), valid: rule4.value }
  140. ])
  141. // 发送邮箱验证码
  142. async function sendEmailCode() {
  143. try {
  144. const res = await personalApi.customUpdateEmailCode({
  145. email: emailInfo.value.email,
  146. oldEmail: emailInfo.value.oldEmail,
  147. });
  148. if (res.code === 200) {
  149. start()
  150. return true;
  151. } else {
  152. showToast(t("Msg.CodeFail"));
  153. return false;
  154. }
  155. } catch (error: any) {
  156. console.log(error, 12);
  157. showToast(t("Msg.CodeFail"));
  158. return false;
  159. }
  160. }
  161. async function handleGetCode() {
  162. if (!emailInfo.value.email) {
  163. showToast(t("vaildate.email.empty"));
  164. return;
  165. }
  166. if (!config.Pattern.Email.test(emailInfo.value.email)) {
  167. showToast(t("vaildate.email.format"));
  168. return;
  169. }
  170. if (!canSend.value) return
  171. await sendEmailCode();
  172. }
  173. // 提交修改邮箱
  174. async function emailUpdate() {
  175. try {
  176. const res = await personalApi.customUpdateEmail({
  177. ...emailInfo.value
  178. });
  179. if (res.code === 200) {
  180. clear()
  181. emailInfo.value = {}
  182. showToast(t("Msg.Success"));
  183. } else {
  184. showToast(res.msg);
  185. }
  186. } catch (error: any) {
  187. showToast(error.msg);
  188. }
  189. }
  190. // 提交修改密码
  191. async function passwordUpdate() {
  192. try {
  193. if (!rule1.value) {
  194. showToast(t("signup.form.rules.1st"));
  195. return;
  196. }
  197. if (!rule2.value) {
  198. showToast(t("signup.form.rules.2nd"));
  199. return;
  200. }
  201. if (!rule4.value) {
  202. showToast(t("signup.form.rules.4rd"));
  203. return;
  204. }
  205. if (passwordInfo.value.newPassword !== passwordInfo.value.checkPass) {
  206. showToast(t("vaildate.password.same"));
  207. return;
  208. }
  209. const res = await personalApi.customUpdatePassword({
  210. ...passwordInfo.value
  211. });
  212. if (res.code === 200) {
  213. // start()
  214. showToast(t("Msg.Success"));
  215. } else {
  216. showToast(res.msg);
  217. }
  218. } catch (error: any) {
  219. showToast(error.msg);
  220. }
  221. }
  222. onMounted(() => {
  223. restore()
  224. })
  225. </script>
  226. <style scoped lang="scss">
  227. @import "@/uni.scss";
  228. :deep(.uni-row1) {
  229. .uni-col {
  230. }
  231. .uni-forms-item {
  232. min-height: px2rpx(79);
  233. margin-bottom: px2rpx(10);
  234. }
  235. .uni-easyinput__content {
  236. //border: none !important;
  237. background-color: transparent;
  238. //background-color: var(--color-zinc-100) !important;
  239. }
  240. }
  241. .btn {
  242. width: 100%;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. padding: px2rpx(12) 0;
  247. background-color: var(--color-error);
  248. color: white;
  249. border: none;
  250. font-size: px2rpx(16);
  251. cursor: pointer;
  252. margin-bottom: px2rpx(24);
  253. }
  254. .notice-list {
  255. margin: 0;
  256. padding: 0 px2rpx(12) px2rpx(12) 0;
  257. .notice-item {
  258. font-size: px2rpx(14);
  259. color: var(--bs-emphasis-color);
  260. line-height: px2rpx(24);
  261. &::before {
  262. content: '●';
  263. display: inline-block;
  264. font-size: px2rpx(10);
  265. margin-right: px2rpx(4);
  266. }
  267. }
  268. .isOK {
  269. color: var(--bs-success);
  270. }
  271. }
  272. .email-code {
  273. display: flex;
  274. align-items: flex-end;
  275. :deep(.email-code-item) {
  276. flex: 1;
  277. .uni-easyinput__content{
  278. border-radius: px2rpx(8) 0 0 px2rpx(8);
  279. }
  280. }
  281. .btn-code {
  282. width: 30%;
  283. margin-bottom: px2rpx(10);
  284. padding: px2rpx(10) px2rpx(16);
  285. background-color: #102047;
  286. color: #fff;
  287. height: 3rem;
  288. text-align: center;
  289. border-radius: 0 25px 25px 0;
  290. cursor: pointer;
  291. font-size: 14px;
  292. flex-shrink: 0;
  293. }
  294. }
  295. </style>