hy-app 0.4.1 → 0.4.2

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.
@@ -1,106 +0,0 @@
1
- <template>
2
- <view class="user-login">
3
- <u-form
4
- :model="phoneForm"
5
- ref="formRef"
6
- :rules="phoneRules"
7
- labelWidth="30"
8
- >
9
- <!--手机号输入-->
10
- <u-form-item prop="phone">
11
- <u-input
12
- v-model="phoneForm.phone"
13
- placeholder="请输入手机号"
14
- :clearable="true"
15
- border="bottom"
16
- >
17
- <!-- #ifndef APP-PLUS-NVUE -->
18
- <template #prefix>
19
- <u-icon name="phone" :color="themeColor"></u-icon>
20
- </template>
21
- <!-- #endif -->
22
- </u-input>
23
- </u-form-item>
24
-
25
- <!--验证码输入-->
26
- <u-form-item prop="code">
27
- <u-input
28
- v-model="phoneForm.code"
29
- border="bottom"
30
- placeholder="请填写验证码"
31
- :color="themeColor"
32
- >
33
- <!-- #ifndef APP-PLUS-NVUE -->
34
- <template #prefix>
35
- <u-icon name="fingerprint" :color="themeColor"></u-icon>
36
- </template>
37
- <!-- #endif -->
38
- </u-input>
39
- <!-- #ifndef APP-PLUS-NVUE -->
40
- <template #right>
41
- <u-button
42
- text="获取验证码"
43
- :color="themeColor"
44
- size="mini"
45
- ></u-button>
46
- </template>
47
- <!-- #endif -->
48
- </u-form-item>
49
- </u-form>
50
- </view>
51
- </template>
52
-
53
- <script setup lang="ts">
54
- import { reactive, ref } from "vue";
55
- import { storeToRefs } from "pinia";
56
- import { useUserInfo } from "../../store";
57
-
58
- interface IProps {
59
- themeColor: string;
60
- customPhoneValidator: Record<string, any>;
61
- }
62
-
63
- const props = withDefaults(defineProps<IProps>(), {
64
- themeColor: "",
65
- customPhoneValidator: () => ({})
66
- });
67
-
68
- const userInfoStore = useUserInfo();
69
- const { phoneForm } = storeToRefs(userInfoStore);
70
- const formRef = ref(null);
71
-
72
- const phoneRules = reactive({
73
- phone: [
74
- {
75
- required: true,
76
- message: "请先输入手机号",
77
- // 可以单个或者同时写两个触发验证方式
78
- trigger: ["change"]
79
- },
80
- props.customPhoneValidator
81
- ],
82
- code: [
83
- {
84
- type: "string",
85
- required: true,
86
- message: "请输入验证码",
87
- // 可以单个或者同时写两个触发验证方式
88
- trigger: ["blur", "change"]
89
- }
90
- ]
91
- });
92
-
93
- /**
94
- * 登录效验
95
- * */
96
- const loginFn = () => {
97
- return new Promise((resolve) => {
98
- formRef.value.validate().then((res) => {
99
- resolve();
100
- });
101
- });
102
- };
103
- defineExpose({
104
- loginFn
105
- });
106
- </script>
@@ -1,271 +0,0 @@
1
- <template>
2
- <view class="user-login">
3
- <HyForm
4
- ref="form_1Ref"
5
- :columns="userColumns"
6
- :formData="userForm"
7
- :input="{ border: 'bottom' }"
8
- ></HyForm>
9
-
10
- <!-- 记住密码 -->
11
- <view class="mui-input-row mui-checkbox">
12
- <HyCheckbox
13
- :columns="rememberList"
14
- shape="square"
15
- :active-color="themeColor"
16
- v-model="rememberPsw"
17
- @change="checkboxChange"
18
- ></HyCheckbox>
19
- </view>
20
- </view>
21
- </template>
22
-
23
- <script setup lang="ts">
24
- import { ref, reactive, onMounted, computed } from 'vue'
25
- import { onHide } from '@dcloudio/uni-app'
26
- import { storeToRefs } from 'pinia'
27
- import { useUserInfo } from '../../store'
28
- import { decryptData, encryptData } from '../../utils'
29
- import { FormTypeEnum } from '../../typing'
30
- import { IconConfig } from '../../config'
31
- import type { UserLoginInfoVo } from './typing'
32
-
33
- // 组件
34
- import HyCheckbox from '../hy-checkbox/hy-checkbox.vue'
35
- import HyForm from '@/package/components/hy-form-group/hy-form-group.vue'
36
-
37
- interface IProps {
38
- themeColor: string
39
- prefix: string
40
- isShowPwd: boolean
41
- userPlaceholder: string
42
- pwdPlaceholder: string
43
- customUserValidator: Record<string, any>
44
- customPwdValidator: Record<string, any>
45
- userNumValidator: Record<string, any>
46
- pwdNumValidator: Record<string, any>
47
- }
48
-
49
- const props = withDefaults(defineProps<IProps>(), {
50
- themeColor: '',
51
- prefix: 'hy',
52
- isShowPwd: false,
53
- userPlaceholder: '',
54
- pwdPlaceholder: '',
55
- customUserValidator: () => ({}),
56
- customPwdValidator: () => ({}),
57
- userNumValidator: () => ({}),
58
- pwdNumValidator: () => ({}),
59
- })
60
- const emit = defineEmits(['handleHistory', 'handleCheckbox'])
61
- const userInfoStore = useUserInfo()
62
- const { userForm, choiceList, rememberPsw } = storeToRefs(userInfoStore)
63
-
64
- const showChoice = ref<boolean>(false)
65
- const showPwd = ref<boolean>(false)
66
- const userColumns = computed(() => [
67
- {
68
- field: 'userName',
69
- label: '',
70
- type: FormTypeEnum.TEXT,
71
- input: {
72
- clearable: true,
73
- placeholder: props.userPlaceholder,
74
- prefixIcon: {
75
- name: IconConfig.MINE,
76
- color: props.themeColor,
77
- },
78
- suffixIcon: {
79
- name: showChoice.value ? IconConfig.ARROW_UP_FILL : IconConfig.ARROW_DOWN_FILL,
80
- color: props.themeColor,
81
- },
82
- onSuffix: () => {
83
- showChoice.value = !showChoice.value
84
- },
85
- },
86
- rules: [props.customUserValidator, props.userNumValidator],
87
- },
88
- {
89
- field: 'password',
90
- label: '',
91
- type: showPwd.value ? FormTypeEnum.TEXT : FormTypeEnum.PASSWORD,
92
- input: {
93
- clearable: true,
94
- placeholder: props.pwdPlaceholder,
95
- prefixIcon: {
96
- name: IconConfig.LOCK,
97
- color: props.themeColor,
98
- },
99
- suffixIcon: {
100
- name: showPwd.value ? IconConfig.EYE : IconConfig.EYE_CLOSE,
101
- color: props.themeColor,
102
- },
103
- onSuffix: () => {
104
- showPwd.value = !showPwd.value
105
- },
106
- },
107
- rules: [props.customUserValidator, props.pwdNumValidator],
108
- },
109
- ])
110
- const rememberList = reactive([{ label: '记住密码', value: 1 }])
111
- const form_1Ref = ref<InstanceType<typeof HyForm>>()
112
- // 效验用户名和密码
113
- const userRules = reactive({
114
- userName: [
115
- {
116
- required: true,
117
- message: '请先输入账号',
118
- // 可以单个或者同时写两个触发验证方式
119
- trigger: ['blur', 'change'],
120
- },
121
- props.customUserValidator,
122
- props.userNumValidator,
123
- ],
124
- password: [
125
- {
126
- required: true,
127
- message: '请输入密码',
128
- // 可以单个或者同时写两个触发验证方式
129
- trigger: ['blur', 'change'],
130
- },
131
- props.pwdNumValidator,
132
- props.customPwdValidator,
133
- ],
134
- })
135
- const rememberPassword = ref(false)
136
- const account = uni.getStorageSync(`${props.prefix}_account`)
137
- const accountList = uni.getStorageSync(`${props.prefix}_choiceList`)
138
-
139
- onMounted(() => {
140
- if (!account) return
141
- const result = decryptData(account)
142
- console.log(result)
143
- //有缓存就赋值给文本没有就清空
144
- rememberPsw.value = result?.rememberPsw
145
- //获取缓存的账号和密码
146
- userForm.value.userName = result?.userName
147
- userForm.value.password = result?.password
148
-
149
- if (accountList) {
150
- choiceList.value = decryptData(accountList) as UserLoginInfoVo[]
151
- }
152
- })
153
-
154
- onHide(() => {
155
- // if (!account) return;
156
- //获取缓存的账号和密码
157
- const { userName, password } = decryptData(account)
158
- if (choiceList.value.length) {
159
- // 过滤数判断是否有一样的账号
160
- const filterArr = choiceList.value.filter((item) => {
161
- return item.user === userName
162
- })
163
- // 有一样的账号退出函数不执行下面的
164
- if (filterArr.length) return
165
- }
166
- // 判断是否有保存账号和密码
167
- if (userName && password) {
168
- // 数组前面加数据
169
- choiceList.value.unshift({
170
- user: userName,
171
- pwd: password,
172
- })
173
- // 数组最多只放三个账号
174
- if (choiceList.value.length >= 5) {
175
- choiceList.value.splice(5, 1)
176
- }
177
- uni.setStorageSync(`${props.prefix}_choiceList`, encryptData(choiceList.value))
178
- }
179
- })
180
-
181
- /**
182
- * 登录效验
183
- * */
184
- const loginFn = () => {
185
- return new Promise((resolve, reject) => {
186
- form_1Ref.value
187
- ?.handleSubmit()
188
- .then((res) => {
189
- resolve('success' + res)
190
- })
191
- .catch((err) => {
192
- reject('error' + err)
193
- })
194
- })
195
- }
196
-
197
- /**
198
- * 勾选是否记住密码
199
- * */
200
- const checkboxChange = () => {
201
- emit('handleCheckbox', rememberPassword.value)
202
- }
203
-
204
- /**
205
- * 选择历史账号
206
- * */
207
- const btnChoiceClick = (index: number) => {
208
- showChoice.value = false
209
- userForm.value.name = choiceList.value[index].user
210
- userForm.value.pwd = choiceList.value[index].pwd
211
- emit('handleHistory')
212
- }
213
-
214
- /**
215
- * 长按操作历史账户
216
- * 0-复制
217
- * 1-删除
218
- * */
219
- const extensionFun = (index: number, username: string) => {
220
- switch (index) {
221
- case 0:
222
- const i = choiceList.value.findIndex((item) => item.user === username)
223
- choiceList.value.splice(i, 1)
224
- uni.setStorageSync(`${props.prefix}_choiceList`, encryptData(choiceList.value))
225
- break
226
- default:
227
- break
228
- }
229
- }
230
-
231
- defineExpose({
232
- loginFn,
233
- })
234
- </script>
235
-
236
- <style lang="scss" scoped>
237
- .user-login {
238
- ::v-deep .u-input__content__subfix-icon {
239
- position: relative;
240
-
241
- .dialog-view {
242
- display: flex;
243
- flex-direction: column;
244
- justify-content: center;
245
- border-radius: 20rpx;
246
- border: 1rpx solid #cacaca;
247
- background-color: white;
248
- position: absolute;
249
- overflow: hidden;
250
- top: 50rpx;
251
- right: 10rpx;
252
- z-index: 999;
253
-
254
- .dialog-title {
255
- white-space: nowrap;
256
- height: 100%;
257
- color: #a6a6a6;
258
- overflow: hidden;
259
- font-size: 28rpx;
260
- text-align: center;
261
- padding: 10rpx 30rpx;
262
- border-top: 1rpx solid rgba(128, 128, 128, 0.233);
263
- }
264
- }
265
- }
266
-
267
- .iconfont {
268
- font-size: 40rpx;
269
- }
270
- }
271
- </style>
@@ -1,288 +0,0 @@
1
- <template>
2
- <view class="normal-login-container">
3
- <view class="logo-content align-center flex justify-center">
4
- <image class="image" :src="props.logo" mode="widthFix"></image>
5
- </view>
6
- <!-- 登录 -->
7
- <view class="login-form-content">
8
- <view class="form-top">
9
- <view
10
- class="top-col"
11
- v-for="(item, i) in tabs"
12
- :key="i"
13
- @tap="currentTab = i"
14
- >
15
- <view class="form-top-title">
16
- {{ item.name }}
17
- </view>
18
- <view
19
- :class="i === currentTab ? 'line' : ''"
20
- :style="'background:' + props.themeColor"
21
- ></view>
22
- </view>
23
- </view>
24
- <TheUserLogin
25
- v-if="'user' === indexCode(currentTab)"
26
- ref="userLoginRef"
27
- :themeColor="props.themeColor"
28
- :prefix="props.prefix"
29
- :isShowPwd="isShowPwd"
30
- :userPlaceholder="userPlaceholder"
31
- :pwdPlaceholder="pwdPlaceholder"
32
- :customUserValidator="props.customUserValidator"
33
- :customPwdValidator="props.customPwdValidator"
34
- :userNumValidator="props.userNumValidator"
35
- :pwdNumValidator="props.pwdNumValidator"
36
- @handleCheckbox="handleCheckbox"
37
- />
38
- <ThePhoneLogin
39
- v-if="'phone' === indexCode(currentTab)"
40
- ref="phoneLoginRef"
41
- :themeColor="props.themeColor"
42
- :customPhoneValidator="props.customPhoneValidator"
43
- />
44
- <view class="action-btn">
45
- <HyButton class="login-btn" :color="props.themeColor" @click="loginFn"
46
- >登录
47
- </HyButton>
48
- </view>
49
- <view class="footer">
50
- <view
51
- class="footer__tips"
52
- v-for="(item, i) in menu"
53
- :key="i"
54
- @click="clickMenuFn(i)"
55
- >{{ item }}</view
56
- >
57
- </view>
58
- </view>
59
- </view>
60
- </template>
61
-
62
- <script lang="ts" setup>
63
- import { ref, computed, watch } from "vue";
64
- import { storeToRefs } from "pinia";
65
- import { encryptData } from "../../utils";
66
- import { useUserInfo } from "../../store";
67
- import defaultProps from "./props";
68
- import type IProps from "./typing";
69
-
70
- // 组件
71
- import TheUserLogin from "./TheUserLogin.vue";
72
- import ThePhoneLogin from "./ThePhoneLogin.vue";
73
- import HyButton from "../hy-button/hy-button.vue";
74
-
75
- const props = withDefaults(defineProps<IProps>(), defaultProps);
76
- const emit = defineEmits(["login", "handleClickMenu"]);
77
-
78
- const userInfoStore = useUserInfo();
79
- const { userForm, rememberPsw } = storeToRefs(userInfoStore);
80
- const indexCode = computed(() => {
81
- return (temp: string | number) => {
82
- switch (Number(props.loginType)) {
83
- case 1:
84
- return "user";
85
- case 2:
86
- return "phone";
87
- default:
88
- if (temp == 0) {
89
- return "user";
90
- } else {
91
- return "phone";
92
- }
93
- }
94
- };
95
- });
96
- const selectModel = (temp: number) => {
97
- return new Promise((resolve, reject) => {
98
- switch (Number(props.loginType)) {
99
- case 1:
100
- resolve("user");
101
- break;
102
- case 2:
103
- resolve("phone");
104
- break;
105
- default:
106
- if (temp == 0) {
107
- resolve("user");
108
- } else {
109
- resolve("phone");
110
- }
111
- break;
112
- }
113
- });
114
- };
115
- const tabs = ref([
116
- {
117
- name: "账号登录",
118
- },
119
- {
120
- name: "验证码登录",
121
- },
122
- ]);
123
- const currentTab = ref(0);
124
- const userLoginRef = ref<InstanceType<typeof TheUserLogin>>();
125
- const phoneLoginRef = ref<InstanceType<typeof ThePhoneLogin>>();
126
- watch(
127
- () => Number(props.loginType),
128
- (newVal) => {
129
- tabs.value = computed(() => {
130
- switch (newVal) {
131
- case 1:
132
- return [{ name: "账号登录" }];
133
- case 2:
134
- return [{ name: "验证码登录" }];
135
- default:
136
- return [{ name: "账号登录" }, { name: "验证码登录" }];
137
- }
138
- }).value;
139
- },
140
- { immediate: true, deep: true },
141
- );
142
-
143
- /**
144
- * 登录用户名
145
- * */
146
- const loginFn = async () => {
147
- const type = await selectModel(currentTab.value);
148
- switch (type) {
149
- case "user":
150
- // let user = userForm.value.userName;
151
- // let pwd = userForm.value.password;
152
- await userLoginRef.value?.loginFn();
153
- //缓存账号和密码
154
- if (rememberPsw.value) {
155
- uni.setStorageSync(
156
- `${props.prefix}_account`,
157
- encryptData({
158
- rememberPsw: rememberPsw.value,
159
- ...userForm.value,
160
- }),
161
- );
162
- } else {
163
- // 如果没有选记住密码就移除之前保存的
164
- uni.removeStorageSync(`${props.prefix}_account`);
165
- uni.setStorageSync(
166
- `${props.prefix}_account`,
167
- encryptData({ rememberPsw: rememberPsw.value }),
168
- );
169
- }
170
- emit("login", userForm.value);
171
- break;
172
- case "phone":
173
- await phoneLoginRef.value?.loginFn();
174
- break;
175
- default:
176
- break;
177
- }
178
- };
179
-
180
- /**
181
- * 点击下面小菜单
182
- * */
183
- const clickMenuFn = (index: number) => {
184
- emit("handleClickMenu", index);
185
- };
186
-
187
- /**
188
- * @description 记住密码
189
- * */
190
- const handleCheckbox = () => {};
191
- </script>
192
-
193
- <style lang="scss" scoped>
194
- .normal-login-container {
195
- width: 100%;
196
- height: 100vh;
197
- padding: 0 60rpx;
198
- /* #ifndef APP-PLUS-NVUE */
199
- box-sizing: border-box;
200
- /* #endif */
201
- display: flex;
202
- justify-content: center;
203
- flex-direction: column;
204
- //align-items: center;
205
-
206
- /*logo图片展示*/
207
- .logo-content {
208
- width: 300rpx;
209
- display: flex;
210
- justify-content: center;
211
- align-items: center;
212
- /* #ifndef APP-PLUS-NVUE */
213
- margin: 0 auto 100rpx;
214
- box-sizing: border-box;
215
- height: auto;
216
- .image {
217
- width: 100%;
218
- height: auto;
219
- }
220
- /* #endif */
221
- }
222
-
223
- /*登录模块*/
224
- .login-form-content {
225
- //text-align: center;
226
- box-shadow: 0px 5px 4px 0px rgba(200, 200, 200, 0.5);
227
- border-radius: 10px;
228
- background: #ffffff;
229
- padding: 28rpx 50rpx 50rpx;
230
-
231
- .form-top {
232
- display: flex;
233
- justify-content: space-around;
234
- margin-bottom: 40rpx;
235
-
236
- .top-col {
237
- display: flex;
238
- flex-direction: column;
239
- justify-content: center;
240
- align-items: center;
241
-
242
- .form-top-title {
243
- font-size: 28rpx;
244
- }
245
-
246
- .line {
247
- width: 90rpx;
248
- height: 4rpx;
249
- margin-top: 6rpx;
250
- }
251
- }
252
- }
253
-
254
- .mui-input-row {
255
- display: flex;
256
- /* #ifndef APP-PLUS-NVUE */
257
- justify-self: start;
258
- /* #endif */
259
- margin-top: 27rpx;
260
- }
261
-
262
- .action-btn {
263
- margin-top: 30rpx;
264
- }
265
-
266
- .footer {
267
- display: flex;
268
- justify-content: space-around;
269
- /* #ifndef APP-PLUS-NVUE */
270
- margin: auto 20%;
271
- /* #endif */
272
-
273
- &__tips {
274
- font-size: 12px;
275
- margin-top: 27rpx;
276
- text-align: center;
277
- color: grey;
278
- text-decoration: underline;
279
- }
280
- }
281
-
282
- .xieyi {
283
- color: #333;
284
- margin-top: 40rpx;
285
- }
286
- }
287
- }
288
- </style>
@@ -1,32 +0,0 @@
1
- import type IProps from "./typing";
2
-
3
- const defaultProps: IProps = {
4
- logo: "",
5
- loginType: 0,
6
- themeColor: "#20D56E",
7
- prefix: "hy",
8
- isShowPwd: false,
9
- userPlaceholder: "输入您的用户名",
10
- pwdPlaceholder: "输入您的密码",
11
- menu: ["立即注册", "忘记密码?"],
12
- customUserValidator: () => ({}),
13
- customPwdValidator: () => ({}),
14
- userNumValidator: () => ({}),
15
- pwdNumValidator: () => ({
16
- min: 6,
17
- max: 20,
18
- message: "长度在6-20个字符之间",
19
- trigger: ["blur", "change"],
20
- }),
21
- customPhoneValidator: () => ({
22
- // 自定义验证函数,见上说明
23
- validator: (rule, value, callback) => {
24
- // 上面有说,返回true表示校验通过,返回false表示不通过
25
- return /^[1][0-9]{10}$/.test(value);
26
- },
27
- message: "手机号码不正确",
28
- trigger: ["change", "blur"],
29
- }),
30
- };
31
-
32
- export default defaultProps;