TerminalChangePasswordDialog.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <cwg-popup :title="props.pwdType == 1 ? t('vu.item3') : t('vu.item4')" :visible="props.visible" :showFooters="false"
  3. @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" 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 rule4 = computed(() => {
  60. return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@&%$^*./\\(\\)\\+\\=#_-])[A-Za-z0-9~!@&%$^*./\\(\\)\\+\\=#_-]{8,16}$/.test(
  61. passwordInfo.value.newPassword
  62. );
  63. });
  64. const noticeItems = computed(() => [
  65. { label: t('signup.form.rules.1st'), valid: rule1.value },
  66. { label: t('signup.form.rules.2nd'), valid: rule2.value },
  67. { label: t('signup.form.rules.4rd'), valid: rule4.value }
  68. ]);
  69. const flag = ref(false); // 防止重复提交
  70. const save = async () => {
  71. if (!rule1.value || !rule2.value || !rule4.value) {
  72. return;
  73. }
  74. if (flag.value) return;
  75. flag.value = true;
  76. try {
  77. let res;
  78. if (props.pwdType == 1) {
  79. // 修改交易账户密码
  80. res = await customApi.ChangeDealPassword({
  81. login: props.account.login,
  82. ...passwordInfo.value
  83. });
  84. } else {
  85. // 修改投资者密码
  86. res = await customApi.ChangeInvestorOassword({
  87. login: props.account.login,
  88. ...passwordInfo.value
  89. });
  90. }
  91. if (res.code == 200) {
  92. showToast(t('Msg.Success'));
  93. emit('update:visible', false);
  94. passwordInfo.value = {
  95. oldPassword: '',
  96. newPassword: ''
  97. }
  98. emit('save');
  99. } else {
  100. showToast(res.msg);
  101. }
  102. } catch (error) {
  103. showToast(error.msg);
  104. emit('update:visible', false);
  105. } finally {
  106. flag.value = false;
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. @import "@/uni.scss";
  112. @media (min-width: 768px) {
  113. :deep(.cwg-dialog) {
  114. background-color: var(--color-white);
  115. border-radius: px2rpx(8);
  116. width: px2rpx(480) !important;
  117. }
  118. }
  119. .popup-content {
  120. padding: px2rpx(16);
  121. }
  122. .account-number {
  123. text-align: left;
  124. display: block;
  125. font-size: px2rpx(14);
  126. color: #141d22;
  127. margin-bottom: px2rpx(24);
  128. }
  129. .crm-form {
  130. :deep(.uni-forms-item) {
  131. margin-bottom: px2rpx(16);
  132. }
  133. :deep(.uni-easyinput__content) {
  134. border: none !important;
  135. background-color: var(--color-zinc-100) !important;
  136. }
  137. }
  138. .notice-list {
  139. margin: px2rpx(10) 0;
  140. padding: 0 px2rpx(12) px2rpx(12) 0;
  141. .notice-item {
  142. text-align: left;
  143. font-size: px2rpx(14);
  144. color: var(--color-yellow-800);
  145. line-height: px2rpx(24);
  146. }
  147. .isOK {
  148. color: var(--color-success);
  149. }
  150. }
  151. .save-btn {
  152. width: 100%;
  153. display: flex;
  154. justify-content: flex-end;
  155. margin-top: px2rpx(20);
  156. .btn {
  157. border: 1px solid rgba(108, 133, 149, 0);
  158. border-radius: px2rpx(8);
  159. padding: px2rpx(8) px2rpx(20);
  160. font-size: px2rpx(14);
  161. color: #2e3a47;
  162. display: inline-flex;
  163. align-items: center;
  164. justify-content: center;
  165. gap: px2rpx(8);
  166. cursor: pointer;
  167. transition: all 0.2s;
  168. height: px2rpx(40);
  169. box-sizing: border-box;
  170. background-color: rgba(108, 133, 149, 0.08);
  171. &.primary {
  172. background-color: var(--color-navy-700);
  173. color: #fff;
  174. &:hover {
  175. background-color: var(--color-navy-600);
  176. }
  177. &[disabled] {
  178. cursor: not-allowed;
  179. }
  180. }
  181. }
  182. }
  183. </style>