create-young-proj 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -1
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
- package/template-uni-app/.vscode/css.code-snippets +398 -0
- package/template-uni-app/.vscode/extensions.json +9 -0
- package/template-uni-app/.vscode/js.code-snippets +1669 -0
- package/template-uni-app/.vscode/settings.json +7 -0
- package/template-uni-app/.vscode/vue-html.code-snippets +668 -0
- package/template-uni-app/README.md +46 -0
- package/template-uni-app/_env +1 -0
- package/template-uni-app/_env.development +11 -0
- package/template-uni-app/_env.production +11 -0
- package/template-uni-app/_env.test +14 -0
- package/template-uni-app/_gitignore +3 -0
- package/template-uni-app/auto-imports.d.ts +404 -0
- package/template-uni-app/components.d.ts +20 -0
- package/template-uni-app/custom-plugins/index.ts +8 -0
- package/template-uni-app/custom-plugins/multiconf.ts +77 -0
- package/template-uni-app/custom-plugins/polyfill.ts +32 -0
- package/template-uni-app/index.html +23 -0
- package/template-uni-app/package.json +84 -0
- package/template-uni-app/pnpm-lock.yaml +7530 -0
- package/template-uni-app/rome.json +26 -0
- package/template-uni-app/src/App.vue +76 -0
- package/template-uni-app/src/apis/index.ts +36 -0
- package/template-uni-app/src/apis/lib/index.ts +236 -0
- package/template-uni-app/src/apis/requests/get.ts +52 -0
- package/template-uni-app/src/apis/requests/index.ts +8 -0
- package/template-uni-app/src/apis/requests/post.ts +23 -0
- package/template-uni-app/src/components/young-loading/young-loading.vue +38 -0
- package/template-uni-app/src/components/young-navbar/young-navbar.vue +253 -0
- package/template-uni-app/src/components/young-tabbar/young-tabbar.vue +137 -0
- package/template-uni-app/src/components/young-tabbar-layout/young-tabbar-layout.vue +27 -0
- package/template-uni-app/src/config/enum.ts +46 -0
- package/template-uni-app/src/config/index.ts +8 -0
- package/template-uni-app/src/config/map.ts +15 -0
- package/template-uni-app/src/env.d.ts +35 -0
- package/template-uni-app/src/main.ts +20 -0
- package/template-uni-app/src/manifest.json +83 -0
- package/template-uni-app/src/pages/index.vue +52 -0
- package/template-uni-app/src/pages/my.vue +29 -0
- package/template-uni-app/src/pages.json +63 -0
- package/template-uni-app/src/store/index.ts +16 -0
- package/template-uni-app/src/store/local/index.ts +40 -0
- package/template-uni-app/src/store/system.ts +12 -0
- package/template-uni-app/src/uni.scss +76 -0
- package/template-uni-app/src/utils/auth.ts +125 -0
- package/template-uni-app/src/utils/index.ts +11 -0
- package/template-uni-app/src/utils/map.ts +97 -0
- package/template-uni-app/src/utils/modal.ts +98 -0
- package/template-uni-app/src/utils/route.ts +149 -0
- package/template-uni-app/src/utils/system.ts +66 -0
- package/template-uni-app/tsconfig.json +13 -0
- package/template-uni-app/unocss.config.ts +30 -0
- package/template-uni-app/vite.config.ts +68 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
<!--
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 17:53:43
|
4
|
+
* @LastEditTime: 2023-07-19 11:56:45
|
5
|
+
* @Description:
|
6
|
+
-->
|
7
|
+
<script lang="ts" setup>
|
8
|
+
onLoad(() => {
|
9
|
+
uni.hideTabBar();
|
10
|
+
});
|
11
|
+
</script>
|
12
|
+
<template>
|
13
|
+
<div>
|
14
|
+
<uni-nav-bar status-bar :border="false" title="个人中心" />
|
15
|
+
<young-tabbar-layout>
|
16
|
+
<h1 class="text-32">我是页面</h1>
|
17
|
+
<view class="uni-primary">主色</view>
|
18
|
+
<view class="uni-success">成功色</view>
|
19
|
+
<view class="uni-warning">警告色</view>
|
20
|
+
<view class="uni-error">错误色</view>
|
21
|
+
|
22
|
+
|
23
|
+
<uni-card title="基础卡片" sub-title="副标题" extra="额外信息"
|
24
|
+
thumbnail="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png">
|
25
|
+
<text>这是一个带头像和双标题的基础卡片,此示例展示了一个完整的卡片。</text>
|
26
|
+
</uni-card>
|
27
|
+
</young-tabbar-layout>
|
28
|
+
</div>
|
29
|
+
</template>
|
@@ -0,0 +1,63 @@
|
|
1
|
+
{
|
2
|
+
"lazyCodeLoading": "requiredComponents",
|
3
|
+
"pages": [
|
4
|
+
{
|
5
|
+
"path": "pages/index",
|
6
|
+
"style": {
|
7
|
+
"navigationBarTitleText": "demo",
|
8
|
+
"navigationBarBackgroundColor": "#E60012",
|
9
|
+
"navigationBarTextStyle": "white",
|
10
|
+
"navigationStyle": "custom"
|
11
|
+
}
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"path": "pages/my",
|
15
|
+
"style": {
|
16
|
+
"navigationBarTitleText": "demo",
|
17
|
+
"navigationBarBackgroundColor": "#E60012",
|
18
|
+
"navigationBarTextStyle": "white",
|
19
|
+
"navigationStyle": "custom"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"tabBar": {
|
24
|
+
"color": "#7A7E83",
|
25
|
+
"selectedColor": "#3cc51f",
|
26
|
+
"borderStyle": "black",
|
27
|
+
"backgroundColor": "#ffffff",
|
28
|
+
"list": [
|
29
|
+
{
|
30
|
+
"pagePath": "pages/index",
|
31
|
+
"text": "首页"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"pagePath": "pages/my",
|
35
|
+
"text": "我的"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
},
|
39
|
+
"globalStyle": {
|
40
|
+
"pageOrientation": "portrait",
|
41
|
+
"navigationBarTitleText": "demo",
|
42
|
+
"navigationBarTextStyle": "white",
|
43
|
+
"navigationBarBackgroundColor": "#0D0D0D",
|
44
|
+
"backgroundColor": "#F2EAE0",
|
45
|
+
"backgroundColorTop": "#F2EAE0",
|
46
|
+
"backgroundColorBottom": "#F4F5F6",
|
47
|
+
"mp-360": {
|
48
|
+
"navigationStyle": "custom"
|
49
|
+
},
|
50
|
+
"h5": {
|
51
|
+
"maxWidth": 1190,
|
52
|
+
"navigationBarTextStyle": "black",
|
53
|
+
"navigationBarBackgroundColor": "#FFFFFF"
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"easycom": {
|
57
|
+
"autoscan": true,
|
58
|
+
"custom": {
|
59
|
+
"^young-(.*)": "@/components/young-$1/young-$1.vue",
|
60
|
+
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 11:21:07
|
4
|
+
* @LastEditTime: 2023-07-18 15:20:22
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { App } from 'vue';
|
8
|
+
import { createPinia } from 'pinia';
|
9
|
+
|
10
|
+
export function setupStore(app: App) {
|
11
|
+
const store = createPinia();
|
12
|
+
app.use(store);
|
13
|
+
}
|
14
|
+
|
15
|
+
export * from './local';
|
16
|
+
export * from './system';
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 15:01:00
|
4
|
+
* @LastEditTime: 2023-07-19 16:50:39
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { randomId } from '@bluesyoung/utils';
|
8
|
+
|
9
|
+
export type LocationInfo = {
|
10
|
+
longitude: string | number;
|
11
|
+
latitude: string | number;
|
12
|
+
city?: string;
|
13
|
+
timer: number;
|
14
|
+
};
|
15
|
+
export type NavInfo = {
|
16
|
+
/**
|
17
|
+
* 系统状态栏高度
|
18
|
+
*/
|
19
|
+
statusBarH: number;
|
20
|
+
/**
|
21
|
+
* 自定义导航栏高度 = 胶囊下距离 + 胶囊上距离 - 状态栏高度
|
22
|
+
*/
|
23
|
+
customBarH: number;
|
24
|
+
/**
|
25
|
+
* 底部安全距离
|
26
|
+
*/
|
27
|
+
safeBottom: number;
|
28
|
+
};
|
29
|
+
|
30
|
+
export const getLocationInfo = () => uni.getStorageSync(YoungStorageKeys.位置信息) as LocationInfo;
|
31
|
+
export const setLocationInfo = (v: LocationInfo) =>
|
32
|
+
uni.setStorageSync(YoungStorageKeys.位置信息, v);
|
33
|
+
export const removeLocationInfo = () => uni.removeStorageSync(YoungStorageKeys.位置信息);
|
34
|
+
|
35
|
+
export const getUuid = () => uni.getStorageSync(YoungStorageKeys.唯一标识) as string;
|
36
|
+
export const setUuid = () =>
|
37
|
+
uni.setStorageSync(YoungStorageKeys.唯一标识, randomId() + randomId() + randomId() + randomId());
|
38
|
+
|
39
|
+
export const setNavbarHeihgt = (v: NavInfo) => uni.setStorageSync(YoungStorageKeys.导航栏高度, v);
|
40
|
+
export const getNavbarHeihgt = () => uni.getStorageSync(YoungStorageKeys.导航栏高度) as NavInfo;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 15:20:04
|
4
|
+
* @LastEditTime: 2023-07-18 15:20:04
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { defineStore } from 'pinia';
|
8
|
+
|
9
|
+
export const useSystemInfo = defineStore('useSystemInfo', () => {
|
10
|
+
const systemInfo = ref<UniApp.GetSystemInfoResult>();
|
11
|
+
return { systemInfo };
|
12
|
+
});
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/**
|
2
|
+
* 这里是uni-app内置的常用样式变量
|
3
|
+
*
|
4
|
+
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
5
|
+
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
|
9
|
+
/**
|
10
|
+
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
11
|
+
*
|
12
|
+
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
13
|
+
*/
|
14
|
+
|
15
|
+
/* 颜色变量 */
|
16
|
+
|
17
|
+
/* 行为相关颜色 */
|
18
|
+
$uni-color-primary: #007aff;
|
19
|
+
$uni-color-success: #4cd964;
|
20
|
+
$uni-color-warning: #f0ad4e;
|
21
|
+
$uni-color-error: #dd524d;
|
22
|
+
|
23
|
+
/* 文字基本颜色 */
|
24
|
+
$uni-text-color:#333;//基本色
|
25
|
+
$uni-text-color-inverse:#fff;//反色
|
26
|
+
$uni-text-color-grey:#999;//辅助灰色,如加载更多的提示信息
|
27
|
+
$uni-text-color-placeholder: #808080;
|
28
|
+
$uni-text-color-disable:#c0c0c0;
|
29
|
+
|
30
|
+
/* 背景颜色 */
|
31
|
+
$uni-bg-color:#ffffff;
|
32
|
+
$uni-bg-color-grey:#f8f8f8;
|
33
|
+
$uni-bg-color-hover:#f1f1f1;//点击状态颜色
|
34
|
+
$uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
|
35
|
+
|
36
|
+
/* 边框颜色 */
|
37
|
+
$uni-border-color:#c8c7cc;
|
38
|
+
|
39
|
+
/* 尺寸变量 */
|
40
|
+
|
41
|
+
/* 文字尺寸 */
|
42
|
+
$uni-font-size-sm:24rpx;
|
43
|
+
$uni-font-size-base:28rpx;
|
44
|
+
$uni-font-size-lg:32rpx;
|
45
|
+
|
46
|
+
/* 图片尺寸 */
|
47
|
+
$uni-img-size-sm:40rpx;
|
48
|
+
$uni-img-size-base:52rpx;
|
49
|
+
$uni-img-size-lg:80rpx;
|
50
|
+
|
51
|
+
/* Border Radius */
|
52
|
+
$uni-border-radius-sm: 4rpx;
|
53
|
+
$uni-border-radius-base: 6rpx;
|
54
|
+
$uni-border-radius-lg: 12rpx;
|
55
|
+
$uni-border-radius-circle: 50%;
|
56
|
+
|
57
|
+
/* 水平间距 */
|
58
|
+
$uni-spacing-row-sm: 10px;
|
59
|
+
$uni-spacing-row-base: 20rpx;
|
60
|
+
$uni-spacing-row-lg: 30rpx;
|
61
|
+
|
62
|
+
/* 垂直间距 */
|
63
|
+
$uni-spacing-col-sm: 8rpx;
|
64
|
+
$uni-spacing-col-base: 16rpx;
|
65
|
+
$uni-spacing-col-lg: 24rpx;
|
66
|
+
|
67
|
+
/* 透明度 */
|
68
|
+
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
|
69
|
+
|
70
|
+
/* 文章场景相关 */
|
71
|
+
$uni-color-title: #2C405A; // 文章标题颜色
|
72
|
+
$uni-font-size-title:40rpx;
|
73
|
+
$uni-color-subtitle: #555555; // 二级标题颜色
|
74
|
+
$uni-font-size-subtitle:36rpx;
|
75
|
+
$uni-color-paragraph: #3F536E; // 文章段落颜色
|
76
|
+
$uni-font-size-paragraph:30rpx;
|
@@ -0,0 +1,125 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 14:28:16
|
4
|
+
* @LastEditTime: 2023-07-19 16:51:04
|
5
|
+
* @Description: 权限相关
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* 获取微信授权码
|
9
|
+
*/
|
10
|
+
export const getWxCode = async () =>
|
11
|
+
new Promise<string>((resolve, reject) => {
|
12
|
+
uni.login({
|
13
|
+
provider: 'weixin',
|
14
|
+
success: (res) => {
|
15
|
+
if (res.errMsg === 'login:ok') {
|
16
|
+
resolve(res.code);
|
17
|
+
} else {
|
18
|
+
reject('wechat auth fail');
|
19
|
+
}
|
20
|
+
},
|
21
|
+
fail: () => {
|
22
|
+
reject('wechat auth fail');
|
23
|
+
},
|
24
|
+
});
|
25
|
+
});
|
26
|
+
|
27
|
+
/**
|
28
|
+
* 定位
|
29
|
+
*/
|
30
|
+
export const locate = (cancelback = true) =>
|
31
|
+
new Promise<UniApp.GetLocationSuccess & { timer?: number }>((_resolve, _reject) => {
|
32
|
+
const position = getLocationInfo();
|
33
|
+
// 系统 getLocation 30s 获取一次 这里延续到 60s
|
34
|
+
if (new Date().getTime() - position.timer < 1000 * 60) {
|
35
|
+
setLocationInfo(position);
|
36
|
+
_resolve(position as unknown as UniApp.GetLocationSuccess);
|
37
|
+
} else {
|
38
|
+
uni.getLocation({
|
39
|
+
type: 'gcj02',
|
40
|
+
success: (res) => {
|
41
|
+
setLocationInfo({
|
42
|
+
latitude: res.latitude,
|
43
|
+
longitude: res.longitude,
|
44
|
+
timer: Date.now(),
|
45
|
+
});
|
46
|
+
|
47
|
+
console.log(res, 'location');
|
48
|
+
_resolve(res);
|
49
|
+
},
|
50
|
+
fail: (res: UniApp.GetLocationSuccess & { errMsg: string }) => {
|
51
|
+
console.log(res, 'location');
|
52
|
+
if (cancelback) {
|
53
|
+
_reject(res);
|
54
|
+
} else {
|
55
|
+
_resolve(position as unknown as UniApp.GetLocationSuccess);
|
56
|
+
}
|
57
|
+
},
|
58
|
+
});
|
59
|
+
}
|
60
|
+
});
|
61
|
+
|
62
|
+
/**
|
63
|
+
* 授权定位
|
64
|
+
* @param {boolean} cancelback 取消授权时是否有回调值
|
65
|
+
*/
|
66
|
+
export const authLocation = async (cancelback = true, isShowModal = true) =>
|
67
|
+
new Promise<UniApp.GetLocationSuccess>(async (resolve, reject) => {
|
68
|
+
uni.getSetting({
|
69
|
+
withSubscriptions: true,
|
70
|
+
success: async (conf) => {
|
71
|
+
if (conf.authSetting['scope.userLocation']) {
|
72
|
+
// 同意过定位授权
|
73
|
+
const position = await locate();
|
74
|
+
uni.$emit(AuthLocationEvents.同意授权, true);
|
75
|
+
resolve(position);
|
76
|
+
} else {
|
77
|
+
try {
|
78
|
+
const position = await locate();
|
79
|
+
uni.$emit(AuthLocationEvents.同意授权, true);
|
80
|
+
resolve(position);
|
81
|
+
} catch (error) {
|
82
|
+
console.log(error);
|
83
|
+
if (isShowModal) {
|
84
|
+
// 是否显示弹窗
|
85
|
+
showModal({
|
86
|
+
title: '获取位置时发生异常,您可点击小程序右上角-设置-允许获取位置',
|
87
|
+
confirmText: '去设置',
|
88
|
+
success: (res) => {
|
89
|
+
if (res.confirm) {
|
90
|
+
uni.openSetting({
|
91
|
+
success: async (e) => {
|
92
|
+
console.log(
|
93
|
+
e.authSetting['scope.userLocation'],
|
94
|
+
`e.authSetting['scope.userLocation']`,
|
95
|
+
);
|
96
|
+
if (e.authSetting['scope.userLocation']) {
|
97
|
+
const position = await locate();
|
98
|
+
resolve(position);
|
99
|
+
} else {
|
100
|
+
reject(false);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
});
|
104
|
+
} else {
|
105
|
+
removeLocationInfo();
|
106
|
+
cancelback && uni.$emit(AuthLocationEvents.启用授权, false);
|
107
|
+
reject(false);
|
108
|
+
}
|
109
|
+
},
|
110
|
+
fail: () => {
|
111
|
+
reject(false);
|
112
|
+
},
|
113
|
+
});
|
114
|
+
} else {
|
115
|
+
reject(false);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
},
|
120
|
+
fail: (conf) => {
|
121
|
+
uni.$emit(AuthLocationEvents.启用授权);
|
122
|
+
reject(false);
|
123
|
+
},
|
124
|
+
});
|
125
|
+
});
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 14:29:41
|
4
|
+
* @LastEditTime: 2023-07-19 16:51:26
|
5
|
+
* @Description: 地图相关(基于腾讯地图)
|
6
|
+
*/
|
7
|
+
export type TxLocationSearchRes = {
|
8
|
+
address: string;
|
9
|
+
title: string;
|
10
|
+
_distance: number;
|
11
|
+
id: string;
|
12
|
+
location: {
|
13
|
+
lat: number;
|
14
|
+
lng: number;
|
15
|
+
};
|
16
|
+
};
|
17
|
+
|
18
|
+
export type TxLocationSearch = {
|
19
|
+
/**
|
20
|
+
* 分页信息
|
21
|
+
*/
|
22
|
+
page_size: number;
|
23
|
+
page_index: number;
|
24
|
+
/**
|
25
|
+
* 搜索关键字
|
26
|
+
*/
|
27
|
+
keyword: string;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* 经纬度
|
31
|
+
*/
|
32
|
+
latitude: number;
|
33
|
+
longitude: number;
|
34
|
+
};
|
35
|
+
|
36
|
+
/**
|
37
|
+
* 地点搜索
|
38
|
+
*/
|
39
|
+
export const searchLoaction = (args: TxLocationSearch) => {
|
40
|
+
const { page_size, page_index, keyword, latitude, longitude } = args;
|
41
|
+
|
42
|
+
return new Promise<TxLocationSearchRes[]>((resolve, reject): void => {
|
43
|
+
uni.request({
|
44
|
+
url: `https://apis.map.qq.com/ws/place/v1/search?boundary=nearby(${latitude},${longitude},1000)${keyword ? `&keyword=${keyword}` : ''
|
45
|
+
}&page_size=${page_size}&page_index=${page_index}&key=${getMapApiKey()}`,
|
46
|
+
success: (res) => {
|
47
|
+
resolve((res.data as unknown as { data: TxLocationSearchRes[] }).data);
|
48
|
+
},
|
49
|
+
fail: (err) => {
|
50
|
+
console.log(err);
|
51
|
+
reject();
|
52
|
+
},
|
53
|
+
complete: (err) => {
|
54
|
+
console.log(err);
|
55
|
+
reject();
|
56
|
+
},
|
57
|
+
});
|
58
|
+
});
|
59
|
+
};
|
60
|
+
|
61
|
+
export type GeoCoderRes = {
|
62
|
+
province_code: string;
|
63
|
+
city_code: string;
|
64
|
+
city: string;
|
65
|
+
province: string;
|
66
|
+
location: {
|
67
|
+
lat: number;
|
68
|
+
lng: number;
|
69
|
+
};
|
70
|
+
};
|
71
|
+
|
72
|
+
/**
|
73
|
+
* 逆地址解析(坐标位置描述)
|
74
|
+
*/
|
75
|
+
export const geocoderLocation = (latitude: number, longitude: number) => {
|
76
|
+
return new Promise<GeoCoderRes>((resolve, reject): void => {
|
77
|
+
uni.request({
|
78
|
+
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${getMapApiKey()}&get_poi=1`,
|
79
|
+
success: (res) => {
|
80
|
+
const ad_info = (res.data as any).result.ad_info;
|
81
|
+
resolve({
|
82
|
+
...ad_info,
|
83
|
+
province_code: ad_info.adcode.slice(0, 2),
|
84
|
+
city_code: ad_info.adcode.slice(0, 4),
|
85
|
+
});
|
86
|
+
},
|
87
|
+
fail: (err) => {
|
88
|
+
console.log(err);
|
89
|
+
reject();
|
90
|
+
},
|
91
|
+
complete: (err) => {
|
92
|
+
console.log(err);
|
93
|
+
reject();
|
94
|
+
},
|
95
|
+
});
|
96
|
+
});
|
97
|
+
};
|
@@ -0,0 +1,98 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 14:12:25
|
4
|
+
* @LastEditTime: 2023-07-18 14:24:22
|
5
|
+
* @Description: ui 交互,弹窗之类的
|
6
|
+
*/
|
7
|
+
import { sleep } from '@bluesyoung/utils';
|
8
|
+
|
9
|
+
let loadingCount = 0;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 显示loading
|
13
|
+
* @param mask - 是否显示遮罩
|
14
|
+
* @param title - 提示文本
|
15
|
+
*/
|
16
|
+
export function showLoading(title = '加载中...', mask = true) {
|
17
|
+
loadingCount++;
|
18
|
+
uni.showLoading({
|
19
|
+
mask,
|
20
|
+
title,
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* 隐藏loading
|
26
|
+
*/
|
27
|
+
export function hideLoading() {
|
28
|
+
--loadingCount === 0 && uni.hideLoading();
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 展示 toast
|
33
|
+
*/
|
34
|
+
export function showToast(options?: UniApp.ShowToastOptions) {
|
35
|
+
const { icon = 'none', mask = false } = options || {};
|
36
|
+
|
37
|
+
uni.showToast({
|
38
|
+
icon,
|
39
|
+
mask,
|
40
|
+
...options,
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
let hasModel = false;
|
45
|
+
const modalPage = new Set<string>();
|
46
|
+
/**
|
47
|
+
* 显示弹窗
|
48
|
+
* ! 全局一次只展示一个弹窗,其他的往后排
|
49
|
+
*/
|
50
|
+
export async function showModal(options: UniApp.ShowModalOptions) {
|
51
|
+
const page = getCurrentPages();
|
52
|
+
const route = page[page.length - 1].route || '';
|
53
|
+
if (modalPage.has(route)) {
|
54
|
+
hasModel = true;
|
55
|
+
} else {
|
56
|
+
hasModel = false;
|
57
|
+
modalPage.add(route);
|
58
|
+
}
|
59
|
+
const { title = '提示', showCancel = true, complete } = options;
|
60
|
+
while (hasModel) {
|
61
|
+
await sleep(0.5);
|
62
|
+
}
|
63
|
+
return new Promise((resolve, reject) => {
|
64
|
+
hasModel = true;
|
65
|
+
uni.showModal({
|
66
|
+
title,
|
67
|
+
showCancel,
|
68
|
+
success(res) {
|
69
|
+
hasModel = false;
|
70
|
+
modalPage.delete(route);
|
71
|
+
if (res.confirm) {
|
72
|
+
resolve(res);
|
73
|
+
} else if (res.cancel) {
|
74
|
+
reject(res);
|
75
|
+
}
|
76
|
+
},
|
77
|
+
fail(err) {
|
78
|
+
hasModel = false;
|
79
|
+
modalPage.delete(route);
|
80
|
+
reject(err);
|
81
|
+
},
|
82
|
+
...options,
|
83
|
+
complete: (res) => {
|
84
|
+
hasModel = false;
|
85
|
+
modalPage.delete(route);
|
86
|
+
complete?.(res);
|
87
|
+
},
|
88
|
+
});
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* 显示错误弹窗 只有确定按钮
|
94
|
+
* @param errMsg - 错误信息
|
95
|
+
*/
|
96
|
+
export function showErrorModal(errMsg: string) {
|
97
|
+
return showModal({ content: errMsg, showCancel: false });
|
98
|
+
}
|