Merge branch 'base' into i18n
This commit is contained in:
commit
48d05961d3
3
env/.env
vendored
3
env/.env
vendored
@ -7,6 +7,9 @@ VITE_WX_APPID = 'wxa2abb91f64032a2b'
|
|||||||
# h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base
|
# h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base
|
||||||
VITE_APP_PUBLIC_BASE=/
|
VITE_APP_PUBLIC_BASE=/
|
||||||
|
|
||||||
|
# 登录页面
|
||||||
|
VITE_LOGIN_URL = '/pages/login/index'
|
||||||
|
|
||||||
VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run'
|
VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run'
|
||||||
VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload'
|
VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload'
|
||||||
|
|
||||||
|
@ -113,6 +113,9 @@ export default defineManifestConfig({
|
|||||||
appid: VITE_WX_APPID,
|
appid: VITE_WX_APPID,
|
||||||
setting: {
|
setting: {
|
||||||
urlCheck: false,
|
urlCheck: false,
|
||||||
|
// 是否启用 ES6 转 ES5
|
||||||
|
es6: true,
|
||||||
|
minified: true,
|
||||||
},
|
},
|
||||||
usingComponents: true,
|
usingComponents: true,
|
||||||
// __usePrivacyCheck__: true,
|
// __usePrivacyCheck__: true,
|
||||||
|
@ -73,10 +73,10 @@
|
|||||||
"prepare": "git init && husky"
|
"prepare": "git init && husky"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"**/*.{html,cjs,json,md,scss,css,txt}": [
|
"**/*.{vue,html,cjs,json,md,scss,css,txt}": [
|
||||||
"prettier --write --cache"
|
"prettier --write --cache"
|
||||||
],
|
],
|
||||||
"**/*.{vue,js,ts}": [
|
"**/*.{js,ts}": [
|
||||||
"oxlint --fix",
|
"oxlint --fix",
|
||||||
"prettier --write --cache"
|
"prettier --write --cache"
|
||||||
],
|
],
|
||||||
|
70
src/App.vue
70
src/App.vue
@ -1,9 +1,61 @@
|
|||||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import
|
<script setup lang="ts">
|
||||||
'abortcontroller-polyfill/dist/abortcontroller-polyfill-only' import { useI18n } from 'vue-i18n'
|
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||||
import { tabBarList, getIsTabbar } from '@/utils/index' onLaunch(() => { console.log('App Launch')
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||||
// #ifdef MP-WEIXIN const setTabbarText = () => { if (!getIsTabbar()) { return } const { t } =
|
import { usePageAuth } from '@/hooks/usePageAuth'
|
||||||
useI18n() const tabbarTexts = tabBarList.map((item) => item.text.replace(/(^%|%$)/g, ''))
|
|
||||||
tabbarTexts.forEach((tabbar: string, index: number) => { console.log('tabbar', tabbar)
|
usePageAuth()
|
||||||
uni.setTabBarItem({ index, text: t(tabbar), }) }) } // fix 微信小程序需要手动调用 api
|
|
||||||
设置一次国际化tabbar text。 setTabbarText() uni.onLocaleChange(setTabbarText) // #endif }) onShow(()
|
onLaunch(() => {
|
||||||
=> { console.log('App Show') }) onHide(() => { console.log('App Hide') })
|
console.log('App Launch')
|
||||||
|
})
|
||||||
|
onShow(() => {
|
||||||
|
console.log('App Show')
|
||||||
|
})
|
||||||
|
onHide(() => {
|
||||||
|
console.log('App Hide')
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
button::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
swiper,
|
||||||
|
scroll-view {
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单行省略,优先使用 unocss: text-ellipsis
|
||||||
|
.ellipsis {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 两行省略
|
||||||
|
.ellipsis-2 {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 三行省略
|
||||||
|
.ellipsis-3 {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-webkit-line-clamp: 3;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
49
src/hooks/usePageAuth.ts
Normal file
49
src/hooks/usePageAuth.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
|
import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils'
|
||||||
|
import { useUserStore } from '@/store'
|
||||||
|
|
||||||
|
const loginRoute = import.meta.env.VITE_LOGIN_URL
|
||||||
|
const isDev = import.meta.env.DEV
|
||||||
|
const isLogined = () => {
|
||||||
|
const userStore = useUserStore()
|
||||||
|
return !!userStore.userInfo.username
|
||||||
|
}
|
||||||
|
// 检查当前页面是否需要登录
|
||||||
|
export function usePageAuth() {
|
||||||
|
onLoad((options) => {
|
||||||
|
// 获取当前页面路径
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const currentPage = pages[pages.length - 1]
|
||||||
|
const currentPath = `/${currentPage.route}`
|
||||||
|
|
||||||
|
// 获取需要登录的页面列表
|
||||||
|
let needLoginPages: string[] = []
|
||||||
|
if (isDev) {
|
||||||
|
needLoginPages = getNeedLoginPages()
|
||||||
|
} else {
|
||||||
|
needLoginPages = _needLoginPages
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查当前页面是否需要登录
|
||||||
|
const isNeedLogin = needLoginPages.includes(currentPath)
|
||||||
|
if (!isNeedLogin) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasLogin = isLogined()
|
||||||
|
if (hasLogin) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建重定向URL
|
||||||
|
const queryString = Object.entries(options || {})
|
||||||
|
.map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
|
||||||
|
.join('&')
|
||||||
|
|
||||||
|
const currentFullPath = queryString ? `${currentPath}?${queryString}` : currentPath
|
||||||
|
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(currentFullPath)}`
|
||||||
|
|
||||||
|
// 重定向到登录页
|
||||||
|
uni.redirectTo({ url: redirectRoute })
|
||||||
|
})
|
||||||
|
}
|
@ -8,7 +8,7 @@ import { useUserStore } from '@/store'
|
|||||||
import { needLoginPages as _needLoginPages, getNeedLoginPages, getLastPage } from '@/utils'
|
import { needLoginPages as _needLoginPages, getNeedLoginPages, getLastPage } from '@/utils'
|
||||||
|
|
||||||
// TODO Check
|
// TODO Check
|
||||||
const loginRoute = '/pages/login/index'
|
const loginRoute = import.meta.env.VITE_LOGIN_URL
|
||||||
|
|
||||||
const isLogined = () => {
|
const isLogined = () => {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user