st-comp 0.0.158 → 0.0.159

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.158",
4
+ "version": "0.0.159",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -0,0 +1,140 @@
1
+ <!-- 修改密码 -->
2
+ <script setup>
3
+ import { ref, reactive, inject, nextTick } from "vue";
4
+ import PasswordPrompt from "../../PasswordPrompt/index.vue";
5
+
6
+ const stConfig = inject("stConfig");
7
+ const PasswordPromptRef = ref(null);
8
+
9
+ const visible = ref(false);
10
+ const ruleFormRef = ref();
11
+ const ruleForm = reactive({
12
+ password: "",
13
+ newPassword: "",
14
+ newPassword2: "",
15
+ });
16
+ const rules = reactive({
17
+ password: [{ required: true, message: "请输入原密码", trigger: "blur" }],
18
+ newPassword: [],
19
+ newPassword2: [
20
+ { required: true, message: "请输入确认密码", trigger: "blur" },
21
+ {
22
+ validator: (rule, value, callback) => {
23
+ if (value === "") {
24
+ callback(new Error("请输入确认密码"));
25
+ } else if (value !== ruleForm.newPassword) {
26
+ callback(new Error("两次输入密码不一致!"));
27
+ } else {
28
+ callback();
29
+ }
30
+ },
31
+ trigger: "blur",
32
+ },
33
+ ],
34
+ });
35
+
36
+ // 当前是否聚焦于密码
37
+ const isFocusNewPassword = ref(false);
38
+
39
+ // 提交
40
+ const handleSubmit = (formEl) => {
41
+ if (!formEl) return;
42
+ formEl.validate(async (valid) => {
43
+ if (!valid) return false;
44
+ await stConfig.request.post("/invest/sys/user/password", ruleForm);
45
+ ElMessage.success(`密码修改成功!`);
46
+ visible.value = false;
47
+ });
48
+ };
49
+
50
+ defineExpose({
51
+ open: () => {
52
+ Object.assign(ruleForm, {
53
+ password: "",
54
+ newPassword: "",
55
+ newPassword2: "",
56
+ });
57
+ visible.value = true;
58
+ // 判断密码校验是否初始化过, 无则初始化
59
+ nextTick(() => {
60
+ if (!rules.newPassword?.length) {
61
+ rules.newPassword = PasswordPromptRef.value?.ruleFormPassword;
62
+ }
63
+ });
64
+ },
65
+ });
66
+ </script>
67
+
68
+ <template>
69
+ <div class="edit-password">
70
+ <el-dialog
71
+ v-model="visible"
72
+ title="修改密码"
73
+ width="460"
74
+ destroy-on-close
75
+ :z-index="200"
76
+ >
77
+ <el-form
78
+ ref="ruleFormRef"
79
+ :rules="rules"
80
+ :model="ruleForm"
81
+ label-width="auto"
82
+ :validate-on-rule-change="false"
83
+ @submit.native.prevent="handleSubmit(ruleFormRef)"
84
+ @keyup.enter.native="handleSubmit(ruleFormRef)"
85
+ >
86
+ <el-form-item
87
+ label="原密码"
88
+ prop="password"
89
+ >
90
+ <el-input
91
+ v-model="ruleForm.password"
92
+ type="password"
93
+ :show-password="true"
94
+ />
95
+ </el-form-item>
96
+ <el-form-item
97
+ label="新密码"
98
+ prop="newPassword"
99
+ >
100
+ <el-input
101
+ v-model="ruleForm.newPassword"
102
+ type="password"
103
+ :show-password="true"
104
+ @focus="
105
+ () => {
106
+ ruleFormRef.clearValidate(['newPassword']);
107
+ isFocusNewPassword = true;
108
+ }
109
+ "
110
+ @blur="isFocusNewPassword = false"
111
+ />
112
+ <PasswordPrompt
113
+ ref="PasswordPromptRef"
114
+ :value="ruleForm.newPassword"
115
+ :isFocus="isFocusNewPassword"
116
+ />
117
+ </el-form-item>
118
+ <el-form-item
119
+ label="确认密码"
120
+ prop="newPassword2"
121
+ >
122
+ <el-input
123
+ v-model="ruleForm.newPassword2"
124
+ type="password"
125
+ :show-password="true"
126
+ />
127
+ </el-form-item>
128
+ </el-form>
129
+ <template #footer>
130
+ <el-button @click="visible = false"> 取消 </el-button>
131
+ <el-button
132
+ type="primary"
133
+ @click="handleSubmit(ruleFormRef)"
134
+ >
135
+ 确认
136
+ </el-button>
137
+ </template>
138
+ </el-dialog>
139
+ </div>
140
+ </template>
@@ -0,0 +1,129 @@
1
+ <!-- 设置密码 -->
2
+ <script setup>
3
+ import { ref, reactive, inject, nextTick } from "vue";
4
+ import PasswordPrompt from "../../PasswordPrompt/index.vue";
5
+
6
+ const stConfig = inject("stConfig");
7
+ const emit = defineEmits(["callBack"]);
8
+ const PasswordPromptRef = ref(null);
9
+
10
+ const visible = ref(false);
11
+ const ruleFormRef = ref();
12
+ const ruleForm = reactive({
13
+ newPassword: "",
14
+ newPassword2: "",
15
+ });
16
+ const rules = reactive({
17
+ newPassword: [],
18
+ newPassword2: [
19
+ { required: true, message: "请输入确认密码", trigger: "blur" },
20
+ {
21
+ validator: (rule, value, callback) => {
22
+ if (value === "") {
23
+ callback(new Error("请输入确认密码"));
24
+ } else if (value !== ruleForm.newPassword) {
25
+ callback(new Error("两次输入密码不一致!"));
26
+ } else {
27
+ callback();
28
+ }
29
+ },
30
+ trigger: "blur",
31
+ },
32
+ ],
33
+ });
34
+
35
+ // 当前是否聚焦于密码
36
+ const isFocusNewPassword = ref(false);
37
+
38
+ // 提交
39
+ const handleSubmit = (formEl) => {
40
+ if (!formEl) return;
41
+ formEl.validate(async (valid) => {
42
+ if (!valid) return false;
43
+ await stConfig.request.post("/invest/sys/user/setPassword", { newPassword: ruleForm.newPassword });
44
+ ElMessage.success(`密码设置成功!`);
45
+ visible.value = false;
46
+ emit("callBack");
47
+ });
48
+ };
49
+
50
+ defineExpose({
51
+ open: () => {
52
+ Object.assign(ruleForm, {
53
+ newPassword: "",
54
+ newPassword2: "",
55
+ });
56
+ visible.value = true;
57
+ // 判断密码校验是否初始化过, 无则初始化
58
+ nextTick(() => {
59
+ if (!rules.newPassword?.length) {
60
+ rules.newPassword = PasswordPromptRef.value?.ruleFormPassword;
61
+ }
62
+ });
63
+ },
64
+ });
65
+ </script>
66
+
67
+ <template>
68
+ <div class="set-password">
69
+ <el-dialog
70
+ v-model="visible"
71
+ title="设置密码"
72
+ width="460"
73
+ destroy-on-close
74
+ :z-index="200"
75
+ >
76
+ <el-form
77
+ ref="ruleFormRef"
78
+ :rules="rules"
79
+ :model="ruleForm"
80
+ label-width="auto"
81
+ :validate-on-rule-change="false"
82
+ @submit.native.prevent="handleSubmit(ruleFormRef)"
83
+ @keyup.enter.native="handleSubmit(ruleFormRef)"
84
+ >
85
+ <el-form-item
86
+ label="密码"
87
+ prop="newPassword"
88
+ >
89
+ <el-input
90
+ v-model="ruleForm.newPassword"
91
+ type="password"
92
+ :show-password="true"
93
+ @focus="
94
+ () => {
95
+ ruleFormRef.clearValidate(['newPassword']);
96
+ isFocusNewPassword = true;
97
+ }
98
+ "
99
+ @blur="isFocusNewPassword = false"
100
+ />
101
+ <PasswordPrompt
102
+ ref="PasswordPromptRef"
103
+ :value="ruleForm.newPassword"
104
+ :isFocus="isFocusNewPassword"
105
+ />
106
+ </el-form-item>
107
+ <el-form-item
108
+ label="确认密码"
109
+ prop="newPassword2"
110
+ >
111
+ <el-input
112
+ v-model="ruleForm.newPassword2"
113
+ type="password"
114
+ :show-password="true"
115
+ />
116
+ </el-form-item>
117
+ </el-form>
118
+ <template #footer>
119
+ <el-button @click="visible = false"> 取消 </el-button>
120
+ <el-button
121
+ type="primary"
122
+ @click="handleSubmit(ruleFormRef)"
123
+ >
124
+ 确认
125
+ </el-button>
126
+ </template>
127
+ </el-dialog>
128
+ </div>
129
+ </template>
@@ -1,114 +1,13 @@
1
- <template>
2
- <div class="user">
3
- <div v-if="userData">
4
- <el-dropdown placement="bottom">
5
- <div class="user-msg">
6
- <el-icon class="user-msg-icon"><UserFilled /></el-icon>
7
- <span>{{ userData?.username }}</span>
8
- <el-icon class="user-msg-arrow"><ArrowDown /></el-icon>
9
- </div>
10
- <template #dropdown>
11
- <el-dropdown-menu>
12
- <el-dropdown-item @click="changePasswordVisible = true">修改密码</el-dropdown-item>
13
- <el-dropdown-item @click="loginoutFn">退出登录</el-dropdown-item>
14
- </el-dropdown-menu>
15
- </template>
16
- </el-dropdown>
17
- </div>
18
- <div
19
- v-else
20
- class="user-login"
21
- @click="loginFn"
22
- >
23
- 前往登录
24
- <el-icon class="user-login-icon"><Right /></el-icon>
25
- </div>
26
-
27
- <!-- 修改密码弹窗 -->
28
- <el-dialog
29
- v-model="changePasswordVisible"
30
- title="修改密码"
31
- width="500"
32
- :z-index="200"
33
- @opened="changePasswordDialogOpen"
34
- @closed="changePasswordDialogClose"
35
- >
36
- <el-form
37
- ref="changePasswordFormRef"
38
- :model="changePasswordForm"
39
- :rules="changePasswordRules"
40
- :validate-on-rule-change="false"
41
- @submit.native.prevent="changePasswordFn"
42
- @keyup.enter.native="changePasswordFn"
43
- label-width="auto"
44
- >
45
- <el-form-item
46
- label="原密码"
47
- prop="oldPassword"
48
- >
49
- <el-input
50
- v-model="changePasswordForm.oldPassword"
51
- type="password"
52
- :show-password="true"
53
- />
54
- </el-form-item>
55
- <el-form-item
56
- label="新密码"
57
- prop="newPassword"
58
- >
59
- <el-input
60
- v-model="changePasswordForm.newPassword"
61
- type="password"
62
- :show-password="true"
63
- @focus="
64
- () => {
65
- changePasswordFormRef.clearValidate(['newPassword']);
66
- isFocusNewPassword = true;
67
- }
68
- "
69
- @blur="isFocusNewPassword = false"
70
- />
71
- <PasswordPrompt
72
- ref="PasswordPromptRef"
73
- :value="changePasswordForm.newPassword"
74
- :isFocus="isFocusNewPassword"
75
- />
76
- </el-form-item>
77
- <el-form-item
78
- label="确认密码"
79
- prop="confirmPassword"
80
- >
81
- <el-input
82
- v-model="changePasswordForm.confirmPassword"
83
- type="password"
84
- :show-password="true"
85
- />
86
- </el-form-item>
87
- </el-form>
88
- <template #footer>
89
- <div class="dialog-footer">
90
- <el-button @click="changePasswordVisible = false">取消</el-button>
91
- <el-button
92
- type="primary"
93
- @click="changePasswordFn"
94
- >
95
- 修改
96
- </el-button>
97
- </div>
98
- </template>
99
- </el-dialog>
100
- </div>
101
- </template>
102
-
103
1
  <script setup>
104
- import { ref, inject, nextTick } from "vue";
2
+ import { reactive, ref } from "vue";
105
3
  import { UserFilled, ArrowDown, Right } from "@element-plus/icons-vue";
106
- import { getUserData, login, loginout } from "st-func";
107
- import PasswordPrompt from "../PasswordPrompt/index.vue";
4
+ import { getUserData, setUserData, login, loginout } from "st-func";
5
+ import SetPasswordDialog from "./components/SetPasswordDialog.vue";
6
+ import EditPasswordDialog from "./components/EditPasswordDialog.vue";
108
7
 
109
- const stConfig = inject("stConfig");
110
- const userData = getUserData();
111
- const PasswordPromptRef = ref(null); // 密码校验强度组件
8
+ const SetPasswordDialogRef = ref(null);
9
+ const EditPasswordDialogRef = ref(null);
10
+ const userData = reactive(getUserData());
112
11
 
113
12
  const emit = defineEmits(["loginout"]);
114
13
  const props = defineProps({
@@ -118,74 +17,72 @@ const props = defineProps({
118
17
  },
119
18
  });
120
19
 
121
- const changePasswordFormRef = ref(null);
122
- const changePasswordVisible = ref(false);
123
- const changePasswordForm = ref({
124
- oldPassword: "",
125
- newPassword: "",
126
- confirmPassword: "",
127
- });
128
- const changePasswordRules = ref({
129
- oldPassword: [{ required: true, message: "请输入原密码", trigger: "blur" }],
130
- newPassword: [],
131
- confirmPassword: [
132
- { required: true, message: "请输入确认密码", trigger: "blur" },
133
- {
134
- validator: (rule, value, callback) => {
135
- if (value === "") {
136
- callback(new Error("请输入确认密码"));
137
- } else if (value !== changePasswordForm.value.newPassword) {
138
- callback(new Error("两次输入密码不一致!"));
139
- } else {
140
- callback();
141
- }
142
- },
143
- trigger: "blur",
144
- },
145
- ],
146
- });
147
- const isFocusNewPassword = ref(false); // 是否聚焦新密码
148
-
149
- const loginFn = () => {
20
+ // 前往登录
21
+ const handleLogin = () => {
150
22
  const { loginUrl } = props.config || {};
151
23
  login(loginUrl);
152
24
  };
153
- const loginoutFn = () => {
25
+ // 退出登录
26
+ const handleLoginOut = () => {
154
27
  const { loginoutToLogin, loginoutUrl } = props.config || {};
155
28
  loginout(loginoutToLogin, loginoutUrl);
156
29
  emit("loginout");
157
30
  };
158
- const changePasswordFn = () => {
159
- changePasswordFormRef.value.validate(async (valid, fields) => {
160
- if (valid) {
161
- const res = await stConfig.request.post("/invest/sys/user/password", {
162
- password: changePasswordForm.value.oldPassword,
163
- newPassword: changePasswordForm.value.newPassword,
164
- newPassword2: changePasswordForm.value.confirmPassword,
165
- });
166
- ElMessage.success(`修改成功!`);
167
- changePasswordVisible.value = false;
168
- } else {
169
- }
170
- });
171
- };
172
- const changePasswordDialogOpen = () => {
173
- if (changePasswordRules.value.newPassword.length === 0) {
174
- nextTick(() => {
175
- changePasswordRules.value.newPassword = PasswordPromptRef.value?.ruleFormPassword;
176
- });
177
- }
178
- };
179
- const changePasswordDialogClose = () => {
180
- changePasswordForm.value = {
181
- oldPassword: "",
182
- newPassword: "",
183
- confirmPassword: "",
184
- };
185
- changePasswordFormRef.value.resetFields();
31
+
32
+ // 设置密码成功回调
33
+ const setPasswordCallBack = () => {
34
+ userData.canSet = false;
35
+ setUserData(userData);
186
36
  };
187
37
  </script>
188
38
 
39
+ <template>
40
+ <div class="user">
41
+ <!-- 已登录: 用户名 -->
42
+ <template v-if="userData">
43
+ <el-dropdown placement="bottom">
44
+ <div class="user-msg">
45
+ <el-icon class="user-msg-icon"><UserFilled /></el-icon>
46
+ <span>{{ userData?.username }}</span>
47
+ <el-icon class="user-msg-arrow"><ArrowDown /></el-icon>
48
+ </div>
49
+ <template #dropdown>
50
+ <el-dropdown-menu>
51
+ <el-dropdown-item
52
+ v-if="userData.canSet"
53
+ @click="SetPasswordDialogRef?.open()"
54
+ >
55
+ 设置密码
56
+ </el-dropdown-item>
57
+ <el-dropdown-item
58
+ v-else
59
+ @click="EditPasswordDialogRef?.open()"
60
+ >
61
+ 修改密码
62
+ </el-dropdown-item>
63
+ <el-dropdown-item @click="handleLoginOut">退出登录</el-dropdown-item>
64
+ </el-dropdown-menu>
65
+ </template>
66
+ </el-dropdown>
67
+ </template>
68
+ <!-- 未登录: 前往登录 -->
69
+ <template v-else>
70
+ <div
71
+ class="user-login"
72
+ @click="handleLogin"
73
+ >
74
+ 前往登录
75
+ <el-icon class="user-login-icon"><Right /></el-icon>
76
+ </div>
77
+ </template>
78
+ <SetPasswordDialog
79
+ ref="SetPasswordDialogRef"
80
+ @callBack="setPasswordCallBack"
81
+ />
82
+ <EditPasswordDialog ref="EditPasswordDialogRef" />
83
+ </div>
84
+ </template>
85
+
189
86
  <style lang="scss" scoped>
190
87
  .user {
191
88
  display: inline-block;