bestuni 1.0.0 → 2.0.0
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/.env +7 -0
- package/.env.development +4 -0
- package/.env.production +4 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/package.json +69 -14
- package/src/App.vue +32 -0
- package/src/env.d.ts +17 -0
- package/src/main.ts +17 -0
- package/src/manifest.json +58 -0
- package/src/pages/index/index.vue +79 -0
- package/src/pages/mine/index.vue +82 -0
- package/src/pages.json +44 -0
- package/src/stores/app.ts +60 -0
- package/src/stores/index.ts +2 -0
- package/src/stores/user.ts +74 -0
- package/src/styles/index.scss +131 -0
- package/src/styles/variables.scss +38 -0
- package/src/uni.scss +4 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/request.ts +100 -0
- package/src/utils/router.ts +88 -0
- package/tsconfig.json +37 -0
- package/uno.config.ts +45 -0
- package/vite.config.ts +72 -0
- package/index.js +0 -73
- package/template/basic/.env +0 -3
- package/template/basic/.env.development +0 -3
- package/template/basic/.env.production +0 -3
- package/template/basic/.eslintrc-auto-import.json +0 -103
- package/template/basic/.eslintrc.js +0 -23
- package/template/basic/.prettierrc.js +0 -14
- package/template/basic/.vscode/settings.json +0 -23
- package/template/basic/index.html +0 -20
- package/template/basic/package.json +0 -93
- package/template/basic/pnpm-lock.yaml +0 -11048
- package/template/basic/shims-uni.d.ts +0 -10
- package/template/basic/src/App.vue +0 -18
- package/template/basic/src/api/user.ts +0 -17
- package/template/basic/src/enums/constantEnums.ts +0 -11
- package/template/basic/src/enums/request.ts +0 -22
- package/template/basic/src/env.d.ts +0 -8
- package/template/basic/src/hooks/useRequest.ts +0 -38
- package/template/basic/src/hooks/useUpload.ts +0 -170
- package/template/basic/src/main.ts +0 -11
- package/template/basic/src/manifest.json +0 -71
- package/template/basic/src/pages/index/index.vue +0 -21
- package/template/basic/src/pages/tabBar/index.vue +0 -7
- package/template/basic/src/pages/tabBar/records.vue +0 -7
- package/template/basic/src/pages/tabBar/user.vue +0 -7
- package/template/basic/src/pages.json +0 -68
- package/template/basic/src/request/cancel.ts +0 -29
- package/template/basic/src/request/http.ts +0 -150
- package/template/basic/src/request/index.ts +0 -98
- package/template/basic/src/request/type.d.ts +0 -30
- package/template/basic/src/shime-uni.d.ts +0 -6
- package/template/basic/src/static/tabbar/home.png +0 -0
- package/template/basic/src/static/tabbar/home_s.png +0 -0
- package/template/basic/src/static/tabbar/news.png +0 -0
- package/template/basic/src/static/tabbar/news_s.png +0 -0
- package/template/basic/src/static/tabbar/user.png +0 -0
- package/template/basic/src/static/tabbar/user_s.png +0 -0
- package/template/basic/src/stores/index.ts +0 -17
- package/template/basic/src/stores/user.ts +0 -117
- package/template/basic/src/types/auto-import.d.ts +0 -189
- package/template/basic/src/types/pinia.d.ts +0 -0
- package/template/basic/src/types/type.ts +0 -21
- package/template/basic/src/uni.scss +0 -76
- package/template/basic/src/utils/cache.ts +0 -50
- package/template/basic/src/utils/config.ts +0 -29
- package/template/basic/src/utils/env.ts +0 -13
- package/template/basic/tsconfig.json +0 -21
- package/template/basic/uno.config.ts +0 -99
- package/template/basic/vite.config.ts +0 -27
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { ref, computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
export interface UserInfo {
|
|
5
|
+
id: string
|
|
6
|
+
nickname: string
|
|
7
|
+
avatar: string
|
|
8
|
+
phone?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const useUserStore = defineStore('user', () => {
|
|
12
|
+
// 用户信息
|
|
13
|
+
const userInfo = ref<UserInfo | null>(null)
|
|
14
|
+
|
|
15
|
+
// Token
|
|
16
|
+
const token = ref<string>('')
|
|
17
|
+
|
|
18
|
+
// 是否已登录
|
|
19
|
+
const isLoggedIn = computed(() => !!token.value && !!userInfo.value)
|
|
20
|
+
|
|
21
|
+
// 设置用户信息
|
|
22
|
+
const setUserInfo = (info: UserInfo) => {
|
|
23
|
+
userInfo.value = info
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 设置 Token
|
|
27
|
+
const setToken = (value: string) => {
|
|
28
|
+
token.value = value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 登录
|
|
32
|
+
const login = async (data: { token: string; userInfo: UserInfo }) => {
|
|
33
|
+
token.value = data.token
|
|
34
|
+
userInfo.value = data.userInfo
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 登出
|
|
38
|
+
const logout = () => {
|
|
39
|
+
token.value = ''
|
|
40
|
+
userInfo.value = null
|
|
41
|
+
|
|
42
|
+
// 跳转到登录页
|
|
43
|
+
uni.reLaunch({
|
|
44
|
+
url: '/pages/index/index'
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 获取用户信息
|
|
49
|
+
const fetchUserInfo = async () => {
|
|
50
|
+
// TODO: 调用接口获取用户信息
|
|
51
|
+
// const res = await request({ url: '/api/user/info' })
|
|
52
|
+
// setUserInfo(res.data)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
userInfo,
|
|
57
|
+
token,
|
|
58
|
+
isLoggedIn,
|
|
59
|
+
setUserInfo,
|
|
60
|
+
setToken,
|
|
61
|
+
login,
|
|
62
|
+
logout,
|
|
63
|
+
fetchUserInfo
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
persist: {
|
|
67
|
+
key: 'smt-user',
|
|
68
|
+
storage: {
|
|
69
|
+
getItem: (key) => uni.getStorageSync(key),
|
|
70
|
+
setItem: (key, value) => uni.setStorageSync(key, value)
|
|
71
|
+
},
|
|
72
|
+
pick: ['token', 'userInfo']
|
|
73
|
+
}
|
|
74
|
+
})
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// 全局样式入口
|
|
2
|
+
|
|
3
|
+
// 重置样式
|
|
4
|
+
page {
|
|
5
|
+
background-color: $bg-color;
|
|
6
|
+
font-size: $font-size-md;
|
|
7
|
+
color: $text-color;
|
|
8
|
+
line-height: 1.5;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 安全区域适配
|
|
12
|
+
.safe-area-bottom {
|
|
13
|
+
padding-bottom: constant(safe-area-inset-bottom);
|
|
14
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 通用布局类
|
|
18
|
+
.flex {
|
|
19
|
+
display: flex;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.flex-center {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.flex-between {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: space-between;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.flex-col {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.flex-1 {
|
|
40
|
+
flex: 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 文本工具类
|
|
44
|
+
.text-center {
|
|
45
|
+
text-align: center;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.text-ellipsis {
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
text-overflow: ellipsis;
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.text-primary {
|
|
55
|
+
color: $primary-color;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.text-success {
|
|
59
|
+
color: $success-color;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.text-warning {
|
|
63
|
+
color: $warning-color;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.text-danger {
|
|
67
|
+
color: $danger-color;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.text-secondary {
|
|
71
|
+
color: $text-color-secondary;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 间距工具类
|
|
75
|
+
.mt-xs {
|
|
76
|
+
margin-top: $spacing-xs;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.mt-sm {
|
|
80
|
+
margin-top: $spacing-sm;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.mt-md {
|
|
84
|
+
margin-top: $spacing-md;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.mt-lg {
|
|
88
|
+
margin-top: $spacing-lg;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.mt-xl {
|
|
92
|
+
margin-top: $spacing-xl;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.mb-xs {
|
|
96
|
+
margin-bottom: $spacing-xs;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.mb-sm {
|
|
100
|
+
margin-bottom: $spacing-sm;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.mb-md {
|
|
104
|
+
margin-bottom: $spacing-md;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.mb-lg {
|
|
108
|
+
margin-bottom: $spacing-lg;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.mb-xl {
|
|
112
|
+
margin-bottom: $spacing-xl;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.px-md {
|
|
116
|
+
padding-left: $spacing-md;
|
|
117
|
+
padding-right: $spacing-md;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.py-md {
|
|
121
|
+
padding-top: $spacing-md;
|
|
122
|
+
padding-bottom: $spacing-md;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 卡片样式
|
|
126
|
+
.card {
|
|
127
|
+
background-color: $bg-color-light;
|
|
128
|
+
border-radius: $border-radius;
|
|
129
|
+
padding: $spacing-md;
|
|
130
|
+
margin: $spacing-md;
|
|
131
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// 全局 SCSS 变量
|
|
2
|
+
// 可在此处覆盖 smt-ui 的默认变量
|
|
3
|
+
|
|
4
|
+
// 品牌色
|
|
5
|
+
$primary-color: #1989fa;
|
|
6
|
+
$success-color: #07c160;
|
|
7
|
+
$warning-color: #ff976a;
|
|
8
|
+
$danger-color: #fa5151;
|
|
9
|
+
|
|
10
|
+
// 文字颜色
|
|
11
|
+
$text-color: #323233;
|
|
12
|
+
$text-color-secondary: #969799;
|
|
13
|
+
$text-color-light: #c8c9cc;
|
|
14
|
+
|
|
15
|
+
// 背景色
|
|
16
|
+
$bg-color: #f7f8fa;
|
|
17
|
+
$bg-color-light: #ffffff;
|
|
18
|
+
|
|
19
|
+
// 边框
|
|
20
|
+
$border-color: #ebedf0;
|
|
21
|
+
$border-radius: 16rpx;
|
|
22
|
+
|
|
23
|
+
// 间距
|
|
24
|
+
$spacing-xs: 8rpx;
|
|
25
|
+
$spacing-sm: 16rpx;
|
|
26
|
+
$spacing-md: 24rpx;
|
|
27
|
+
$spacing-lg: 32rpx;
|
|
28
|
+
$spacing-xl: 48rpx;
|
|
29
|
+
|
|
30
|
+
// 字号
|
|
31
|
+
$font-size-xs: 20rpx;
|
|
32
|
+
$font-size-sm: 24rpx;
|
|
33
|
+
$font-size-md: 28rpx;
|
|
34
|
+
$font-size-lg: 32rpx;
|
|
35
|
+
$font-size-xl: 36rpx;
|
|
36
|
+
|
|
37
|
+
// 动画
|
|
38
|
+
$animation-duration: 0.3s;
|
package/src/uni.scss
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useUserStore } from '@/stores'
|
|
2
|
+
|
|
3
|
+
export interface RequestOptions {
|
|
4
|
+
url: string
|
|
5
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
6
|
+
data?: Record<string, any>
|
|
7
|
+
header?: Record<string, string>
|
|
8
|
+
showLoading?: boolean
|
|
9
|
+
loadingText?: string
|
|
10
|
+
showError?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ResponseData<T = any> {
|
|
14
|
+
code: number
|
|
15
|
+
message: string
|
|
16
|
+
data: T
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 基础 URL
|
|
20
|
+
const BASE_URL = import.meta.env.VITE_API_BASE_URL || ''
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 统一请求封装
|
|
24
|
+
*/
|
|
25
|
+
export const request = <T = any>(options: RequestOptions): Promise<ResponseData<T>> => {
|
|
26
|
+
const userStore = useUserStore()
|
|
27
|
+
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
// 显示 Loading
|
|
30
|
+
if (options.showLoading !== false) {
|
|
31
|
+
uni.showLoading({
|
|
32
|
+
title: options.loadingText || '加载中...',
|
|
33
|
+
mask: true
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
uni.request({
|
|
38
|
+
url: BASE_URL + options.url,
|
|
39
|
+
method: options.method || 'GET',
|
|
40
|
+
data: options.data,
|
|
41
|
+
header: {
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
'Authorization': userStore.token ? `Bearer ${userStore.token}` : '',
|
|
44
|
+
...options.header
|
|
45
|
+
},
|
|
46
|
+
success: (res) => {
|
|
47
|
+
const data = res.data as ResponseData<T>
|
|
48
|
+
|
|
49
|
+
if (data.code === 0 || data.code === 200) {
|
|
50
|
+
resolve(data)
|
|
51
|
+
} else if (data.code === 401) {
|
|
52
|
+
// Token 过期,执行登出
|
|
53
|
+
userStore.logout()
|
|
54
|
+
reject(new Error('登录已过期,请重新登录'))
|
|
55
|
+
} else {
|
|
56
|
+
// 显示错误提示
|
|
57
|
+
if (options.showError !== false) {
|
|
58
|
+
uni.showToast({
|
|
59
|
+
title: data.message || '请求失败',
|
|
60
|
+
icon: 'none'
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
reject(new Error(data.message))
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
fail: (err) => {
|
|
67
|
+
// 显示网络错误提示
|
|
68
|
+
if (options.showError !== false) {
|
|
69
|
+
uni.showToast({
|
|
70
|
+
title: '网络请求失败',
|
|
71
|
+
icon: 'none'
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
reject(err)
|
|
75
|
+
},
|
|
76
|
+
complete: () => {
|
|
77
|
+
if (options.showLoading !== false) {
|
|
78
|
+
uni.hideLoading()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 快捷方法
|
|
86
|
+
export const get = <T = any>(url: string, data?: Record<string, any>, options?: Partial<RequestOptions>) => {
|
|
87
|
+
return request<T>({ url, method: 'GET', data, ...options })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const post = <T = any>(url: string, data?: Record<string, any>, options?: Partial<RequestOptions>) => {
|
|
91
|
+
return request<T>({ url, method: 'POST', data, ...options })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const put = <T = any>(url: string, data?: Record<string, any>, options?: Partial<RequestOptions>) => {
|
|
95
|
+
return request<T>({ url, method: 'PUT', data, ...options })
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const del = <T = any>(url: string, data?: Record<string, any>, options?: Partial<RequestOptions>) => {
|
|
99
|
+
return request<T>({ url, method: 'DELETE', data, ...options })
|
|
100
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由跳转工具
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface NavigateOptions {
|
|
6
|
+
url: string
|
|
7
|
+
params?: Record<string, any>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 拼接 URL 参数
|
|
12
|
+
*/
|
|
13
|
+
const buildUrl = (url: string, params?: Record<string, any>): string => {
|
|
14
|
+
if (!params || Object.keys(params).length === 0) {
|
|
15
|
+
return url
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const queryString = Object.entries(params)
|
|
19
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
20
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
21
|
+
.join('&')
|
|
22
|
+
|
|
23
|
+
return url.includes('?') ? `${url}&${queryString}` : `${url}?${queryString}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 普通跳转
|
|
28
|
+
*/
|
|
29
|
+
export const navigateTo = (options: NavigateOptions | string) => {
|
|
30
|
+
const opts = typeof options === 'string' ? { url: options } : options
|
|
31
|
+
uni.navigateTo({
|
|
32
|
+
url: buildUrl(opts.url, opts.params)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 重定向(关闭当前页)
|
|
38
|
+
*/
|
|
39
|
+
export const redirectTo = (options: NavigateOptions | string) => {
|
|
40
|
+
const opts = typeof options === 'string' ? { url: options } : options
|
|
41
|
+
uni.redirectTo({
|
|
42
|
+
url: buildUrl(opts.url, opts.params)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 返回上一页
|
|
48
|
+
*/
|
|
49
|
+
export const navigateBack = (delta = 1) => {
|
|
50
|
+
uni.navigateBack({ delta })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 切换 Tab
|
|
55
|
+
*/
|
|
56
|
+
export const switchTab = (url: string) => {
|
|
57
|
+
uni.switchTab({ url })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 关闭所有页面并跳转
|
|
62
|
+
*/
|
|
63
|
+
export const reLaunch = (options: NavigateOptions | string) => {
|
|
64
|
+
const opts = typeof options === 'string' ? { url: options } : options
|
|
65
|
+
uni.reLaunch({
|
|
66
|
+
url: buildUrl(opts.url, opts.params)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 获取当前页面路径
|
|
72
|
+
*/
|
|
73
|
+
export const getCurrentPath = (): string => {
|
|
74
|
+
const pages = getCurrentPages()
|
|
75
|
+
if (pages.length === 0) return ''
|
|
76
|
+
const currentPage = pages[pages.length - 1]
|
|
77
|
+
return '/' + currentPage.route
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 获取当前页面参数
|
|
82
|
+
*/
|
|
83
|
+
export const getCurrentQuery = (): Record<string, any> => {
|
|
84
|
+
const pages = getCurrentPages()
|
|
85
|
+
if (pages.length === 0) return {}
|
|
86
|
+
const currentPage = pages[pages.length - 1] as any
|
|
87
|
+
return currentPage.options || currentPage.$page?.options || {}
|
|
88
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"jsx": "preserve",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"lib": [
|
|
13
|
+
"ESNext",
|
|
14
|
+
"DOM"
|
|
15
|
+
],
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"paths": {
|
|
19
|
+
"@/*": [
|
|
20
|
+
"./src/*"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"types": [
|
|
24
|
+
"@dcloudio/types",
|
|
25
|
+
"@types/node"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"include": [
|
|
29
|
+
"src/**/*.ts",
|
|
30
|
+
"src/**/*.d.ts",
|
|
31
|
+
"src/**/*.vue"
|
|
32
|
+
],
|
|
33
|
+
"exclude": [
|
|
34
|
+
"node_modules",
|
|
35
|
+
"dist"
|
|
36
|
+
]
|
|
37
|
+
}
|
package/uno.config.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
presetAttributify,
|
|
4
|
+
presetIcons,
|
|
5
|
+
presetUno,
|
|
6
|
+
transformerDirectives,
|
|
7
|
+
transformerVariantGroup,
|
|
8
|
+
} from 'unocss'
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
presets: [
|
|
12
|
+
presetUno(),
|
|
13
|
+
presetAttributify(),
|
|
14
|
+
presetIcons({
|
|
15
|
+
scale: 1.2,
|
|
16
|
+
warn: true,
|
|
17
|
+
extraProperties: {
|
|
18
|
+
'display': 'inline-block',
|
|
19
|
+
'vertical-align': 'middle',
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
transformers: [
|
|
24
|
+
transformerDirectives(),
|
|
25
|
+
transformerVariantGroup(),
|
|
26
|
+
],
|
|
27
|
+
rules: [
|
|
28
|
+
[/^content-\[(.*)\]$/, ([, s]) => ({ content: `'${s}'` })],
|
|
29
|
+
],
|
|
30
|
+
theme: {
|
|
31
|
+
colors: {
|
|
32
|
+
primary: '#1989fa',
|
|
33
|
+
success: '#07c160',
|
|
34
|
+
warning: '#ff976a',
|
|
35
|
+
danger: '#fa5151',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
shortcuts: {
|
|
39
|
+
'flex-center': 'flex items-center justify-center',
|
|
40
|
+
'flex-between': 'flex items-center justify-between',
|
|
41
|
+
'flex-col': 'flex flex-col',
|
|
42
|
+
'text-ellipsis': 'overflow-hidden whitespace-nowrap overflow-ellipsis',
|
|
43
|
+
'card': 'bg-white rd-4 p-4 m-4',
|
|
44
|
+
},
|
|
45
|
+
})
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
import { defineConfig, loadEnv } from 'vite'
|
|
3
|
+
import uni from '@dcloudio/vite-plugin-uni'
|
|
4
|
+
import UnoCSS from 'unocss/vite'
|
|
5
|
+
import AutoImport from 'unplugin-auto-import/vite'
|
|
6
|
+
import Components from 'unplugin-vue-components/vite'
|
|
7
|
+
|
|
8
|
+
// https://vitejs.dev/config/
|
|
9
|
+
export default defineConfig(({ mode }) => {
|
|
10
|
+
const env = loadEnv(mode, process.cwd())
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
plugins: [
|
|
14
|
+
// UniApp 插件
|
|
15
|
+
uni(),
|
|
16
|
+
|
|
17
|
+
// UnoCSS 原子化 CSS
|
|
18
|
+
UnoCSS(),
|
|
19
|
+
|
|
20
|
+
// 自动导入 API
|
|
21
|
+
AutoImport({
|
|
22
|
+
imports: [
|
|
23
|
+
'vue',
|
|
24
|
+
'pinia',
|
|
25
|
+
{
|
|
26
|
+
'@/utils': ['request', 'get', 'post', 'navigateTo', 'redirectTo', 'navigateBack', 'switchTab', 'reLaunch'],
|
|
27
|
+
'@/stores': ['useAppStore', 'useUserStore']
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
dts: 'src/auto-imports.d.ts',
|
|
31
|
+
dirs: ['src/composables'],
|
|
32
|
+
vueTemplate: true
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
// 自动导入组件
|
|
36
|
+
Components({
|
|
37
|
+
dts: 'src/components.d.ts',
|
|
38
|
+
// 自定义组件解析器
|
|
39
|
+
resolvers: [
|
|
40
|
+
// smt-ui 组件自动导入
|
|
41
|
+
(componentName) => {
|
|
42
|
+
if (componentName.startsWith('Mt')) {
|
|
43
|
+
const name = componentName.slice(2).replace(/([A-Z])/g, '-$1').toLowerCase().slice(1)
|
|
44
|
+
return {
|
|
45
|
+
name: componentName,
|
|
46
|
+
from: '@sumintong/smt-ui',
|
|
47
|
+
sideEffects: `@sumintong/smt-ui/src/components/${name}/${name}.scss`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
],
|
|
54
|
+
resolve: {
|
|
55
|
+
alias: {
|
|
56
|
+
'@': resolve(__dirname, 'src')
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
server: {
|
|
60
|
+
host: '0.0.0.0',
|
|
61
|
+
port: 9000,
|
|
62
|
+
open: true
|
|
63
|
+
},
|
|
64
|
+
css: {
|
|
65
|
+
preprocessorOptions: {
|
|
66
|
+
scss: {
|
|
67
|
+
additionalData: `@import "@/styles/variables.scss";`
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
package/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { promisify } = require('util')
|
|
3
|
-
const { resolve } = require('path')
|
|
4
|
-
const { blue, green, red } = require('kolorist')
|
|
5
|
-
const argv = require('minimist')(process.argv.slice(2))
|
|
6
|
-
const { existsSync, readJsonSync } = require('fs-extra')
|
|
7
|
-
const download = promisify(require('download-git-repo'))
|
|
8
|
-
const prompts = require('prompts')
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
// 获取项目名称
|
|
12
|
-
const targetDir = argv._[0] || 'my-unibest-app'
|
|
13
|
-
const cwd = process.cwd()
|
|
14
|
-
const root = resolve(cwd, targetDir)
|
|
15
|
-
|
|
16
|
-
// 验证目录
|
|
17
|
-
if (existsSync(root)) {
|
|
18
|
-
console.log(red(`✖ 目录 ${targetDir} 已存在`))
|
|
19
|
-
process.exit(1)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 交互式选项
|
|
23
|
-
const options = await prompts([
|
|
24
|
-
{
|
|
25
|
-
type: 'select',
|
|
26
|
-
name: 'template',
|
|
27
|
-
message: '选择模板类型',
|
|
28
|
-
choices: [
|
|
29
|
-
{ title: '基础模板', value: 'basic' },
|
|
30
|
-
{ title: '高级模板 (含状态管理)', value: 'advanced' }
|
|
31
|
-
]
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
type: 'toggle',
|
|
35
|
-
name: 'typescript',
|
|
36
|
-
message: '启用 TypeScript?',
|
|
37
|
-
initial: true,
|
|
38
|
-
active: 'yes',
|
|
39
|
-
inactive: 'no'
|
|
40
|
-
}
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
// 下载模板
|
|
44
|
-
console.log(blue('⬇ 正在下载模板...'))
|
|
45
|
-
await download('github:yourname/unibest-template#main', root, {
|
|
46
|
-
clone: true,
|
|
47
|
-
headers: { 'User-Agent': 'create-unibest' }
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
// 修改 package.json
|
|
51
|
-
const pkgPath = resolve(root, 'package.json')
|
|
52
|
-
const pkg = readJsonSync(pkgPath)
|
|
53
|
-
pkg.name = targetDir
|
|
54
|
-
writeJsonSync(pkgPath, pkg, { spaces: 2 })
|
|
55
|
-
|
|
56
|
-
// 完成提示
|
|
57
|
-
console.log(green('✓ 项目创建成功!'))
|
|
58
|
-
console.log(`
|
|
59
|
-
进入项目目录:
|
|
60
|
-
cd ${targetDir}
|
|
61
|
-
|
|
62
|
-
安装依赖:
|
|
63
|
-
pnpm install
|
|
64
|
-
|
|
65
|
-
启动开发服务器:
|
|
66
|
-
pnpm dev
|
|
67
|
-
`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
main().catch(err => {
|
|
71
|
-
console.error(red('✖ 创建失败:'), err)
|
|
72
|
-
process.exit(1)
|
|
73
|
-
})
|
package/template/basic/.env
DELETED