TerminalChangePasswordDialog.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <cwg-popup :title="props.pwdType == 1 ? t('Custom.Settings.LoginPwd') : t('Custom.Settings.InvestorPwd')"
  3. :visible="props.visible" :showFooter="false" @update:visible="$emit('update:visible', $event)">
  4. <view class="popup-content">
  5. <text class="account-number">{{ accountLabel }} {{ account.login }}</text>
  6. <uni-forms :model="passwordInfo" labelWidth="200" label-position="top" class="crm-form">
  7. <uni-forms-item
  8. :label="props.pwdType == 1 ? t('Custom.Settings.LoginPwdOld') : t('Custom.Settings.InvestorPwdOld')">
  9. <uni-easyinput type="password" :clearable="false" v-model="passwordInfo.oldPassword"
  10. :placeholder="props.pwdType == 1 ? t('Custom.Settings.LoginPwdOld') : t('Custom.Settings.InvestorPwdOld')" />
  11. </uni-forms-item>
  12. <uni-forms-item :label="t('Custom.Settings.NewPwd')">
  13. <uni-easyinput type="password" :clearable="false" v-model="passwordInfo.newPassword"
  14. :placeholder="t('Custom.Settings.NewPwd')" />
  15. </uni-forms-item>
  16. </uni-forms>
  17. <view class="notice-list">
  18. <view v-for="(item, index) in noticeItems" :key="index"
  19. :class="['notice-item', item.valid ? 'isOK' : '']">
  20. {{ item.label }}
  21. </view>
  22. </view>
  23. <view class="save-btn">
  24. <view class="btn primary" @click="save" :disabled="!isFormValid" v-t="'Btn.Save'" />
  25. </view>
  26. </view>
  27. </cwg-popup>
  28. </template>
  29. <script setup>
  30. import { ref, computed } from 'vue'
  31. import { customApi } from '@/service/custom';
  32. import { useI18n } from 'vue-i18n'
  33. import { showToast } from "@/utils/toast";
  34. const { t } = useI18n()
  35. const props = defineProps({
  36. visible: { type: Boolean, default: false },
  37. account: { type: Object, default: () => ({}) },
  38. accountLabel: { type: String, default: '账户: #' },
  39. // 1: 交易密码, 2: 投资者密码
  40. pwdType: { type: [Number, String], default: 1 },
  41. })
  42. const emit = defineEmits(['update:visible', 'save'])
  43. const passwordInfo = ref({
  44. oldPassword: '',
  45. newPassword: ''
  46. });
  47. const rule1 = computed(() => {
  48. if (!passwordInfo.value.newPassword) return false;
  49. return /^.{8,16}$/.test(passwordInfo.value.newPassword);
  50. });
  51. const rule2 = computed(() => {
  52. return /^(?=.*?[a-z])(?=.*?[A-Z]).*$/.test(passwordInfo.value.newPassword);
  53. });
  54. const rule3 = computed(() => {
  55. return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?!.*([~!@&%$^\\(\\)#_]).*\\1.*\\1)[A-Za-z0-9~!@&%$^\\(\\)#_]{8,16}$/.test(
  56. passwordInfo.value.newPassword
  57. );
  58. });
  59. const noticeItems = computed(() => [
  60. { label: t('signup.form.rules.1st'), valid: rule1.value },
  61. { label: t('signup.form.rules.2nd'), valid: rule2.value },
  62. { label: t('signup.form.rules.3rd'), valid: rule3.value }
  63. ]);
  64. const isFormValid = computed(() => {
  65. return rule1.value && rule2.value && rule3.value && passwordInfo.value.oldPassword && passwordInfo.value.newPassword;
  66. });
  67. const flag = ref(false); // 防止重复提交
  68. const save = async () => {
  69. if (!isFormValid.value) {
  70. return;
  71. }
  72. if (flag.value) return;
  73. flag.value = true;
  74. try {
  75. let res;
  76. if (props.pwdType == 1) {
  77. // 修改交易账户密码
  78. res = await customApi.ChangeDealPassword({
  79. login: props.account.login,
  80. ...passwordInfo.value
  81. });
  82. } else {
  83. // 修改投资者密码
  84. res = await customApi.ChangeInvestorOassword({
  85. login: props.account.login,
  86. ...passwordInfo.value
  87. });
  88. }
  89. if (res.code == 200) {
  90. showToast(t('Msg.Success'));
  91. emit('update:visible', false);
  92. passwordInfo.value = {
  93. oldPassword: '',
  94. newPassword: ''
  95. }
  96. emit('save');
  97. } else {
  98. showToast(res.msg);
  99. }
  100. } catch (error) {
  101. console.error(error);
  102. } finally {
  103. flag.value = false;
  104. }
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. @import "@/uni.scss";
  109. @media (min-width: 768px) {
  110. :deep(.cwg-dialog) {
  111. background-color: var(--color-white);
  112. border-radius: px2rpx(8);
  113. width: px2rpx(480) !important;
  114. }
  115. }
  116. .popup-content {
  117. padding: px2rpx(16);
  118. }
  119. .account-number {
  120. display: block;
  121. font-size: px2rpx(14);
  122. color: #141d22;
  123. margin-bottom: px2rpx(24);
  124. }
  125. .crm-form {
  126. :deep(.uni-forms-item) {
  127. margin-bottom: px2rpx(16);
  128. }
  129. :deep(.uni-easyinput__content) {
  130. border: none !important;
  131. background-color: var(--color-zinc-100) !important;
  132. }
  133. }
  134. .notice-list {
  135. margin: px2rpx(10) 0;
  136. padding: 0 px2rpx(12) px2rpx(12) 0;
  137. .notice-item {
  138. font-size: px2rpx(14);
  139. color: var(--color-yellow-800);
  140. line-height: px2rpx(24);
  141. }
  142. .isOK {
  143. color: var(--color-success);
  144. }
  145. }
  146. .save-btn {
  147. width: 100%;
  148. display: flex;
  149. justify-content: flex-end;
  150. margin-top: px2rpx(20);
  151. .btn {
  152. border: 1px solid rgba(108, 133, 149, 0);
  153. border-radius: px2rpx(8);
  154. padding: px2rpx(8) px2rpx(20);
  155. font-size: px2rpx(14);
  156. color: #2e3a47;
  157. display: inline-flex;
  158. align-items: center;
  159. justify-content: center;
  160. gap: px2rpx(8);
  161. cursor: pointer;
  162. transition: all 0.2s;
  163. height: px2rpx(40);
  164. box-sizing: border-box;
  165. background-color: rgba(108, 133, 149, 0.08);
  166. &.primary {
  167. background-color: var(--color-navy-700);
  168. color: #fff;
  169. &:hover {
  170. background-color: var(--color-navy-600);
  171. }
  172. &[disabled] {
  173. cursor: not-allowed;
  174. }
  175. }
  176. }
  177. }
  178. </style>