st-comp 0.0.197 → 0.0.199

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.197",
4
+ "version": "0.0.199",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -0,0 +1,144 @@
1
+ <!-- 设置资料 -->
2
+ <script setup>
3
+ import { ref, reactive, inject } from "vue";
4
+ import { getUserData } from "st-func";
5
+
6
+ const stConfig = inject("stConfig");
7
+ const emit = defineEmits(["callBack"]);
8
+ const userData = reactive(getUserData());
9
+
10
+ const visible = ref(false);
11
+ const ruleFormRef = ref();
12
+ const ruleForm = reactive({
13
+ nickName: "",
14
+ email: "",
15
+ mobile: "",
16
+ });
17
+ const rules = reactive({
18
+ nickName: [
19
+ { required: true, message: "请输入昵称", trigger: "blur" },
20
+ {
21
+ validator: (rule, value, callback) => {
22
+ if (/[\s@<>&%]/.test(value)) {
23
+ callback("昵称不能包含空格、@、<、>、&、%等特殊字符");
24
+ } else if (value && value.length > 10) {
25
+ callback("昵称长度不能超过10个字符");
26
+ } else {
27
+ callback();
28
+ }
29
+ },
30
+ trigger: "blur",
31
+ },
32
+ ],
33
+ email: [
34
+ {
35
+ validator: (rule, value, callback) => {
36
+ if (value && !/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(value)) {
37
+ callback("邮箱格式错误");
38
+ } else {
39
+ callback();
40
+ }
41
+ },
42
+ trigger: "blur",
43
+ },
44
+ ],
45
+ mobile: [
46
+ { required: true, message: "请输入手机号", trigger: "blur" },
47
+ {
48
+ validator: (rule, value, callback) => {
49
+ const regex = /^1[3-9]\d{9}$/;
50
+ if (regex.test(value)) {
51
+ callback();
52
+ } else {
53
+ callback("手机号格式错误");
54
+ }
55
+ },
56
+ trigger: "blur",
57
+ },
58
+ ],
59
+ });
60
+
61
+ // 提交
62
+ const handleSubmit = (formEl) => {
63
+ if (!formEl) return;
64
+ formEl.validate(async (valid) => {
65
+ if (!valid) return false;
66
+ // 仅传递修改过的字段
67
+ const params = {
68
+ ...ruleForm,
69
+ userId: userData.id,
70
+ username: userData.username,
71
+ };
72
+ if (params.nickName === userData.nickName) delete params.nickName;
73
+ if (params.email === userData.email) delete params.email;
74
+ if (params.mobile === userData.mobile) delete params.mobile;
75
+ await stConfig.request.post("/invest/sys/user/updateUserInfo", params);
76
+ ElMessage.success(`资料修改成功!`);
77
+ visible.value = false;
78
+ // 设置成功的回调函数
79
+ emit("callBack", ruleForm);
80
+ });
81
+ };
82
+
83
+ defineExpose({
84
+ open: () => {
85
+ Object.assign(userData, getUserData());
86
+ Object.assign(ruleForm, {
87
+ nickName: userData.nickName,
88
+ email: userData.email,
89
+ mobile: userData.mobile,
90
+ });
91
+ visible.value = true;
92
+ },
93
+ });
94
+ </script>
95
+
96
+ <template>
97
+ <div class="edit-info">
98
+ <el-dialog
99
+ v-model="visible"
100
+ title="设置资料"
101
+ width="460"
102
+ destroy-on-close
103
+ :z-index="200"
104
+ >
105
+ <el-form
106
+ ref="ruleFormRef"
107
+ :rules="rules"
108
+ :model="ruleForm"
109
+ label-width="auto"
110
+ :validate-on-rule-change="false"
111
+ @submit.native.prevent="handleSubmit(ruleFormRef)"
112
+ @keyup.enter.native="handleSubmit(ruleFormRef)"
113
+ >
114
+ <el-form-item
115
+ label="昵称"
116
+ prop="nickName"
117
+ >
118
+ <el-input v-model="ruleForm.nickName" />
119
+ </el-form-item>
120
+ <el-form-item
121
+ label="邮箱"
122
+ prop="email"
123
+ >
124
+ <el-input v-model="ruleForm.email" />
125
+ </el-form-item>
126
+ <el-form-item
127
+ label="手机号"
128
+ prop="mobile"
129
+ >
130
+ <el-input v-model="ruleForm.mobile" />
131
+ </el-form-item>
132
+ </el-form>
133
+ <template #footer>
134
+ <el-button @click="visible = false"> 取消 </el-button>
135
+ <el-button
136
+ type="primary"
137
+ @click="handleSubmit(ruleFormRef)"
138
+ >
139
+ 确认
140
+ </el-button>
141
+ </template>
142
+ </el-dialog>
143
+ </div>
144
+ </template>
@@ -2,9 +2,11 @@
2
2
  import { reactive, ref } from "vue";
3
3
  import { UserFilled, ArrowDown, Right } from "@element-plus/icons-vue";
4
4
  import { getUserData, setUserData, login, loginout } from "st-func";
5
+ import EditInfoDialog from "./components/EditInfoDialog.vue";
5
6
  import SetPasswordDialog from "./components/SetPasswordDialog.vue";
6
7
  import EditPasswordDialog from "./components/EditPasswordDialog.vue";
7
8
 
9
+ const EditInfoDialogRef = ref(null);
8
10
  const SetPasswordDialogRef = ref(null);
9
11
  const EditPasswordDialogRef = ref(null);
10
12
  const userData = reactive(getUserData());
@@ -29,6 +31,11 @@ const handleLoginOut = () => {
29
31
  emit("loginout");
30
32
  };
31
33
 
34
+ // 设置资料成功回调
35
+ const editInfoCallBack = (data) => {
36
+ Object.assign(userData, data);
37
+ setUserData(userData);
38
+ };
32
39
  // 设置密码成功回调
33
40
  const setPasswordCallBack = () => {
34
41
  userData.canSet = false;
@@ -43,14 +50,15 @@ const setPasswordCallBack = () => {
43
50
  <el-dropdown placement="bottom">
44
51
  <div class="user-msg">
45
52
  <el-icon class="user-msg-icon"><UserFilled /></el-icon>
46
- <span>{{ userData?.username }}</span>
53
+ <span>{{ userData?.nickName ?? userData?.username }}</span>
47
54
  <el-icon class="user-msg-arrow"><ArrowDown /></el-icon>
48
55
  </div>
49
56
  <template #dropdown>
50
57
  <el-dropdown-menu>
51
58
  <!-- 自定义菜单项插槽 -->
52
59
  <slot name="dropdown-items"></slot>
53
-
60
+ <!-- 基础功能 -->
61
+ <el-dropdown-item @click="EditInfoDialogRef?.open()">设置资料</el-dropdown-item>
54
62
  <el-dropdown-item
55
63
  v-if="userData.canSet"
56
64
  @click="SetPasswordDialogRef?.open()"
@@ -78,10 +86,18 @@ const setPasswordCallBack = () => {
78
86
  <el-icon class="user-login-icon"><Right /></el-icon>
79
87
  </div>
80
88
  </template>
89
+
90
+ <!-- 弹窗: 设置资料 -->
91
+ <EditInfoDialog
92
+ ref="EditInfoDialogRef"
93
+ @callBack="editInfoCallBack"
94
+ />
95
+ <!-- 弹窗: 设置密码 -->
81
96
  <SetPasswordDialog
82
97
  ref="SetPasswordDialogRef"
83
98
  @callBack="setPasswordCallBack"
84
99
  />
100
+ <!-- 弹窗: 修改密码 -->
85
101
  <EditPasswordDialog ref="EditPasswordDialogRef" />
86
102
  </div>
87
103
  </template>
@@ -110,4 +126,4 @@ const setPasswordCallBack = () => {
110
126
  }
111
127
  }
112
128
  }
113
- </style>
129
+ </style>
@@ -1,11 +1,11 @@
1
1
  <template>
2
- <div style="width: 100%; height: 100%">
2
+ <div style="width: 100%; height: 100%; display: flex; justify-content: flex-end;">
3
3
  <st-user
4
4
  :config="config"
5
5
  @loginout="loginoutFn"
6
6
  >
7
7
  <template #dropdown-items>
8
- <el-dropdown-item>自定义菜单项</el-dropdown-item>
8
+ <el-dropdown-item>自定义项</el-dropdown-item>
9
9
  </template>
10
10
  </st-user>
11
11
  </div>