st-comp 0.0.202 → 0.0.203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.202",
4
+ "version": "0.0.203",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -9,16 +9,16 @@ const visible = ref(false);
9
9
  const ruleFormRef = ref();
10
10
  const ruleForm = reactive({
11
11
  mobile: "",
12
+ verifyCode: "",
12
13
  });
13
14
  const rules = reactive({
14
15
  mobile: [
15
16
  { required: true, message: "请输入手机号", trigger: "blur" },
16
17
  {
17
18
  validator: (rule, value, callback) => {
18
- const regex = /^1[3-9]\d{9}$/;
19
19
  if (value === userData.mobile) {
20
20
  callback("新手机号与旧手机号相同");
21
- } else if (!regex.test(value)) {
21
+ } else if (!validatePhone(value)) {
22
22
  callback("手机号格式错误");
23
23
  } else {
24
24
  callback();
@@ -27,8 +27,40 @@ const rules = reactive({
27
27
  trigger: "blur",
28
28
  },
29
29
  ],
30
+ verifyCode: [{ required: true, message: "请输入验证码", trigger: "blur" }],
30
31
  });
31
32
 
33
+ const smsTimer = ref(null);
34
+ const smsInterval = ref(0);
35
+ const smsInterval_init = 60;
36
+
37
+ // 手机号校验
38
+ const validatePhone = (mobile) => {
39
+ return /^1[3-9]\d{9}$/.test(mobile);
40
+ };
41
+ // 获取短信验证码
42
+ const getSms = async () => {
43
+ // 校验手机号格式
44
+ if (!ruleForm.mobile) return false;
45
+ if (!validatePhone(ruleForm.mobile)) return ElMessage.error("手机号格式错误");
46
+
47
+ // 接口请求
48
+ const params = {
49
+ type: 5,
50
+ userId: userData.id,
51
+ mobile: ruleForm.mobile,
52
+ };
53
+ await stConfig.request.post("/invest/sys/commonSms", params);
54
+ ElMessage.success("短信验证码已发送");
55
+
56
+ // 间隔设置
57
+ smsInterval.value = smsInterval_init;
58
+ smsTimer.value = setInterval(() => {
59
+ smsInterval.value -= 1;
60
+ if (smsInterval.value === 0) clearInterval(smsTimer.value);
61
+ }, 1000);
62
+ };
63
+
32
64
  // 打开
33
65
  const handleOpen = () => {
34
66
  ruleForm.mobile = "";
@@ -57,7 +89,12 @@ const handleSubmit = () => {
57
89
 
58
90
  <template>
59
91
  <div class="mobile">
60
- <el-text type="info">{{ userData.mobile ?? "暂无" }}</el-text>
92
+ <el-text
93
+ v-if="userData.mobile"
94
+ type="info"
95
+ >
96
+ {{ userData.mobile }}
97
+ </el-text>
61
98
  <el-text
62
99
  class="btn"
63
100
  size="small"
@@ -69,6 +106,7 @@ const handleSubmit = () => {
69
106
  </div>
70
107
  <!-- 手机号绑定窗口 -->
71
108
  <el-dialog
109
+ modal-class="mobile-dialog"
72
110
  v-model="visible"
73
111
  width="460"
74
112
  title="手机号绑定"
@@ -86,6 +124,33 @@ const handleSubmit = () => {
86
124
  >
87
125
  <el-input v-model="ruleForm.mobile" />
88
126
  </el-form-item>
127
+ <el-form-item
128
+ label="验证码"
129
+ prop="verifyCode"
130
+ >
131
+ <el-input
132
+ class="sms-input"
133
+ v-model="ruleForm.verifyCode"
134
+ placeholder="验证码"
135
+ >
136
+ <template #suffix>
137
+ <span
138
+ v-if="smsInterval"
139
+ class="get-button disabled"
140
+ >
141
+ 重新发送({{ smsInterval }})
142
+ </span>
143
+ <span
144
+ v-else
145
+ class="get-button"
146
+ :class="{ disabled: !ruleForm.mobile }"
147
+ @click.stop="getSms"
148
+ >
149
+ 获取验证码
150
+ </span>
151
+ </template>
152
+ </el-input>
153
+ </el-form-item>
89
154
  </el-form>
90
155
  <template #footer>
91
156
  <el-button @click="visible = false"> 取消 </el-button>
@@ -107,4 +172,19 @@ const handleSubmit = () => {
107
172
  cursor: pointer;
108
173
  }
109
174
  }
175
+ .mobile-dialog {
176
+ .sms-input {
177
+ .get-button {
178
+ color: var(--el-color-primary);
179
+ line-height: 16px;
180
+ border-left: var(--el-border);
181
+ padding-left: 10px;
182
+ cursor: pointer;
183
+ }
184
+ .disabled {
185
+ color: var(--el-color-info);
186
+ cursor: not-allowed;
187
+ }
188
+ }
189
+ }
110
190
  </style>