@zfqh/uniapp 0.3.9 → 0.3.10
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/CHANGELOG.md +8 -0
- package/docs/api/hooks/index.md +62 -3
- package/docs/api/index.md +2 -0
- package/docs/api/mixins/login.md +2 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/useNeedLogin.d.ts +1 -0
- package/lib/hooks/useNeedLogin.js +26 -0
- package/lib/hooks/useReferrer.d.ts +1 -0
- package/lib/hooks/useReferrer.js +11 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.3.10](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.3.9...@zfqh/uniapp@0.3.10) (2026-07-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zfqh/uniapp
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.3.9](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.3.8...@zfqh/uniapp@0.3.9) (2026-07-29)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @zfqh/uniapp
|
package/docs/api/hooks/index.md
CHANGED
|
@@ -18,28 +18,32 @@ const store = useStore();
|
|
|
18
18
|
| `usePopup(visible)` | 接收一个 ref/响应式可见状态,返回 popup ref;visible 为 true 时调用 popup.open(),false 时调用 popup.close()。 |
|
|
19
19
|
| `useVersion()` | 返回 { version },version 包含 name/code;App 端会通过 plus.runtime.getProperty 补齐版本信息。 |
|
|
20
20
|
| `useI18n()` | 非 nvue 直接使用 vue-i18n 的 useI18n;nvue 下返回注入的 t 与本地 locale ref。 |
|
|
21
|
+
| `useReferrer()` | 返回 referrer ref。页面 onLoad 时自动读取 `__referrer` 参数并解码,用于登录页记录来源路径。 |
|
|
22
|
+
| `useNeedLogin(flag = false)` | 页面登录守卫。onShow 时检测登录态,未登录则跳转登录页;flag 为 true 时额外校验当前页面是否在 needLoginPages 列表中。 |
|
|
21
23
|
|
|
22
24
|
## 示例
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
import { ref } from 'vue';
|
|
26
|
-
import { useOverlay, usePopup, useVersion, useI18n } from '@zfqh/uniapp';
|
|
28
|
+
import { useOverlay, usePopup, useVersion, useI18n, useReferrer, useNeedLogin } from '@zfqh/uniapp';
|
|
27
29
|
|
|
28
30
|
const [showOverlay, showChildren] = useOverlay(false, 300);
|
|
29
31
|
const visible = ref(false);
|
|
30
32
|
const popup = usePopup(visible);
|
|
31
33
|
const { version } = useVersion();
|
|
32
34
|
const { t } = useI18n();
|
|
35
|
+
const referrer = useReferrer();
|
|
36
|
+
useNeedLogin();
|
|
33
37
|
```
|
|
34
38
|
|
|
35
39
|
---
|
|
36
40
|
|
|
37
41
|
## Hooks 使用指南
|
|
38
42
|
|
|
39
|
-
根入口导出 `@zfqh/uniapp/lib/hooks`
|
|
43
|
+
根入口导出 `@zfqh/uniapp/lib/hooks` 下的组合式函数:
|
|
40
44
|
|
|
41
45
|
```ts
|
|
42
|
-
import { useOverlay, usePopup, useVersion, useI18n } from '@zfqh/uniapp';
|
|
46
|
+
import { useOverlay, usePopup, useVersion, useI18n, useReferrer, useNeedLogin } from '@zfqh/uniapp';
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
## Store 用法
|
|
@@ -180,3 +184,58 @@ const { t, locale } = useI18n();
|
|
|
180
184
|
<text>{{ t('common.submit') }}</text>
|
|
181
185
|
</template>
|
|
182
186
|
```
|
|
187
|
+
|
|
188
|
+
## useReferrer
|
|
189
|
+
|
|
190
|
+
用于登录页记录来源路径。页面 `onLoad` 时自动读取 `__referrer` 参数并解码,登录成功后可跳回原页面:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { useReferrer } from '@zfqh/uniapp';
|
|
194
|
+
|
|
195
|
+
const referrer = useReferrer();
|
|
196
|
+
|
|
197
|
+
console.log(referrer.value); // 解码后的来源路径
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
返回:
|
|
201
|
+
|
|
202
|
+
| 返回值 | 说明 |
|
|
203
|
+
| --- | --- |
|
|
204
|
+
| `referrer` | 解码后的来源路径 ref;无 `__referrer` 参数时为空字符串。 |
|
|
205
|
+
|
|
206
|
+
配合 `navigate` 在登录成功后跳回来源页:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { useReferrer, navigate, getPage } from '@zfqh/uniapp';
|
|
210
|
+
|
|
211
|
+
const referrer = useReferrer();
|
|
212
|
+
|
|
213
|
+
// 登录成功后
|
|
214
|
+
navigate.reLaunch({ url: referrer.value || getPage('index') });
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## useNeedLogin
|
|
218
|
+
|
|
219
|
+
页面登录守卫,替代 `login` mixin。`onShow` 时检测登录态,未登录则跳转登录页:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { useNeedLogin } from '@zfqh/uniapp';
|
|
223
|
+
|
|
224
|
+
useNeedLogin();
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
| 参数 | 默认值 | 说明 |
|
|
228
|
+
| --- | --- | --- |
|
|
229
|
+
| `flag` | `false` | 为 `true` 时,仅当前页面在 `needLoginPages` 列表中才跳转登录;为 `false` 时未登录即跳转。 |
|
|
230
|
+
|
|
231
|
+
```vue
|
|
232
|
+
<script setup lang="ts">
|
|
233
|
+
import { useNeedLogin } from '@zfqh/uniapp';
|
|
234
|
+
|
|
235
|
+
// 根据 needLoginPages 配置判断
|
|
236
|
+
useNeedLogin(true);
|
|
237
|
+
|
|
238
|
+
// 强制要求登录(不判断列表)
|
|
239
|
+
useNeedLogin();
|
|
240
|
+
</script>
|
|
241
|
+
```
|
package/docs/api/index.md
CHANGED
package/docs/api/mixins/login.md
CHANGED
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useNeedLogin(flag?: boolean): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { onShow } from '@dcloudio/uni-app';
|
|
2
|
+
import { useStore } from 'vuex';
|
|
3
|
+
import page from '../configs/page';
|
|
4
|
+
import { inPages } from '../utils/pages';
|
|
5
|
+
import navigate from '../utils/navigate';
|
|
6
|
+
// #ifdef H5
|
|
7
|
+
import { IS_WEBVIEW_ENV } from '../utils/consts';
|
|
8
|
+
// #endif
|
|
9
|
+
export function useNeedLogin(flag = false) {
|
|
10
|
+
const store = useStore();
|
|
11
|
+
onShow(() => {
|
|
12
|
+
if (uni.showAppFromBackground) {
|
|
13
|
+
// #ifdef H5
|
|
14
|
+
if (IS_WEBVIEW_ENV && store.state.login?.info?.accessToken == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// #endif
|
|
18
|
+
const { route } = getCurrentPages().pop() || {};
|
|
19
|
+
if (!store.getters.isLogin && !!route) {
|
|
20
|
+
if (!flag || inPages(page.needLoginPages, `/${route}`)) {
|
|
21
|
+
navigate({ url: '', needLogin: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useReferrer(): import("vue").Ref<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { onLoad } from '@dcloudio/uni-app';
|
|
3
|
+
export function useReferrer() {
|
|
4
|
+
const referrer = ref('');
|
|
5
|
+
onLoad((options) => {
|
|
6
|
+
if (options?.__referrer) {
|
|
7
|
+
referrer.value = decodeURIComponent(options.__referrer);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return referrer;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zfqh/uniapp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "uniapp公共模块",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/qs": "^6.9.16",
|
|
47
47
|
"@types/url-parse": "^1.4.11"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5a532f7c3044e74a29f402e46836d0b5fa279242"
|
|
50
50
|
}
|