Merge branch 'develop' into develop_daisy
# Conflicts: # src/pages/home/home.vue
This commit is contained in:
commit
df7563be13
@ -1,19 +1,30 @@
|
||||
type ResultCode = 0 | -1 | -2 | 10003
|
||||
|
||||
interface ResultData {
|
||||
message: string
|
||||
data: Record<string, any>
|
||||
}
|
||||
|
||||
export class Result {
|
||||
static codes = {
|
||||
Success: 0,
|
||||
Fail: -1,
|
||||
NotMore: -2,
|
||||
PaySuccessful: 10003
|
||||
Success: 0 as const,
|
||||
Fail: -1 as const,
|
||||
NotMore: -2 as const,
|
||||
PaySuccessful: 10003 as const
|
||||
}
|
||||
|
||||
static resultsMap = new Map([
|
||||
static resultsMap = new Map<ResultCode, ResultData>([
|
||||
[Result.codes.Success, { message: '成功', data: {} }],
|
||||
[Result.codes.Fail, { message: '网络加载失败', data: {} }],
|
||||
[Result.codes.NotMore, { message: '没有更多', data: {} }],
|
||||
[Result.codes.PaySuccessful, { message: '支付成功', data: {} }]
|
||||
])
|
||||
|
||||
constructor(code, data, message) {
|
||||
code: ResultCode
|
||||
message: string
|
||||
data: Record<string, any>
|
||||
|
||||
constructor(code: ResultCode, data?: Record<string, any>, message?: string) {
|
||||
const result = Result.resultsMap.get(code)
|
||||
if (result) {
|
||||
this.code = code
|
||||
@ -27,22 +38,22 @@ export class Result {
|
||||
}
|
||||
|
||||
// 成功
|
||||
static get Success() {
|
||||
static get Success(): Result {
|
||||
return new Result(Result.codes.Success)
|
||||
}
|
||||
|
||||
// 失败(默认错误)
|
||||
static get Fail() {
|
||||
static get Fail(): Result {
|
||||
return new Result(Result.codes.Fail)
|
||||
}
|
||||
|
||||
// 没有更多
|
||||
static get NotMore() {
|
||||
static get NotMore(): Result {
|
||||
return new Result(Result.codes.NotMore)
|
||||
}
|
||||
|
||||
// 支付成功
|
||||
static get PaySuccessful() {
|
||||
static get PaySuccessful(): Result {
|
||||
return new Result(Result.codes.PaySuccessful)
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,24 +6,19 @@
|
||||
import { useUserStore } from '@/store'
|
||||
import { getNeedLoginPages, needLoginPages as _needLoginPages } from '@/utils'
|
||||
|
||||
// TODO Check
|
||||
const loginRoute = '/pages/login/index'
|
||||
const loginRoute = '/pages/login/login'
|
||||
|
||||
const isLogined = () => {
|
||||
const loginStatus = () => {
|
||||
const userStore = useUserStore()
|
||||
return userStore.isLogined
|
||||
return userStore.loginStatus
|
||||
}
|
||||
|
||||
const isDev = import.meta.env.DEV
|
||||
|
||||
// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
|
||||
const navigateToInterceptor = {
|
||||
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
|
||||
invoke({ url }: { url: string }) {
|
||||
// console.log(url) // /pages/route-interceptor/index?name=feige&age=30
|
||||
const path = url.split('?')[0]
|
||||
let needLoginPages: string[] = []
|
||||
// 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
|
||||
if (isDev) {
|
||||
needLoginPages = getNeedLoginPages()
|
||||
} else {
|
||||
@ -33,12 +28,11 @@ const navigateToInterceptor = {
|
||||
if (!isNeedLogin) {
|
||||
return true
|
||||
}
|
||||
const hasLogin = isLogined()
|
||||
const hasLogin = loginStatus()
|
||||
if (hasLogin) {
|
||||
return true
|
||||
}
|
||||
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}`
|
||||
uni.navigateTo({ url: redirectRoute })
|
||||
uni.navigateTo({ url: loginRoute })
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,8 @@
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
"needLogin": false
|
||||
},
|
||||
{
|
||||
"path": "pages/get-code/get-code",
|
||||
@ -76,7 +77,8 @@
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
"needLogin": false
|
||||
},
|
||||
{
|
||||
"path": "pages/info-publish/info-publish",
|
||||
@ -104,7 +106,8 @@
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
"needLogin": false
|
||||
},
|
||||
{
|
||||
"path": "pages/mine/mine",
|
||||
@ -120,7 +123,8 @@
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"disableScroll": true
|
||||
}
|
||||
},
|
||||
"needLogin": false
|
||||
},
|
||||
{
|
||||
"path": "pages/workbench/workbench",
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
style: {
|
||||
navigationStyle: 'custom',
|
||||
disableScroll: true
|
||||
}
|
||||
},
|
||||
needLogin: false
|
||||
}
|
||||
</route>
|
||||
<template>
|
||||
@ -42,6 +43,7 @@
|
||||
import { PlatId } from '@/typings'
|
||||
import { Result } from '@/constants/result'
|
||||
import { useBasicStore, useUserStore } from '@/store'
|
||||
import GetSystemInfoResult = UniNamespace.GetSystemInfoResult
|
||||
|
||||
const $basic = useBasicStore()
|
||||
const $user = useUserStore()
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
style: {
|
||||
navigationStyle: 'custom',
|
||||
disableScroll: true
|
||||
}
|
||||
},
|
||||
needLogin: false
|
||||
}
|
||||
</route>
|
||||
<template>
|
||||
@ -32,7 +33,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { phoneRegExp } from '@/constants/regular-expressions'
|
||||
import { AccountChannel, CodeType, IResData } from '@/typings'
|
||||
import { AccountChannel, CodeType } from '@/typings'
|
||||
import { getCodeApi, UserGetCodeRequest } from '@/service/user'
|
||||
import { Result } from '@/constants/result'
|
||||
|
||||
@ -54,7 +55,7 @@
|
||||
mask: true
|
||||
})
|
||||
try {
|
||||
const result: IResData = await getCodeApi<UserGetCodeRequest>({
|
||||
const result = await getCodeApi<UserGetCodeRequest>({
|
||||
account: phone.value,
|
||||
channel: AccountChannel.phone,
|
||||
codeType: CodeType.reset
|
||||
|
||||
@ -7,23 +7,29 @@
|
||||
}
|
||||
</route>
|
||||
<template>
|
||||
<view class="custom-bg-default">
|
||||
<view v-if="systemInfo" :style="{ marginTop: systemInfo.safeAreaInsets?.top + 'px' }">
|
||||
<view v-if="$user.loginStatus">
|
||||
<view class="h-12 pt-1 flex flex-items-center flex-justify-between mx-4">
|
||||
<view>
|
||||
<view>19104656的互联</view>
|
||||
</view>
|
||||
</view>
|
||||
<CustomTab class="mt-10" :list="featuresList" @clickItem="clickItem"></CustomTab>
|
||||
<button class="mt-12" @click="$user.logout">退出登录</button>
|
||||
</view>
|
||||
<view v-else>
|
||||
<button class="mt-12" @click="toLogin">去登录</button>
|
||||
<button class="mt-12" @click="logout">退出登录</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import CustomTab from '@/pages/home/CustomTab.vue'
|
||||
import { useUserStore } from '@/store'
|
||||
import { useBasicStore, useUserStore } from '@/store'
|
||||
import { Result } from '@/constants/result'
|
||||
import { HomeTab, TabBarItem } from '@/typings'
|
||||
|
||||
const $user = useUserStore()
|
||||
const $basic = useBasicStore()
|
||||
|
||||
const systemInfo = ref(null)
|
||||
|
||||
const list = ref<Array<TabBarItem>>([
|
||||
{
|
||||
@ -180,21 +186,21 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '信息发布',
|
||||
title: '其他',
|
||||
list: [
|
||||
{
|
||||
id: 70,
|
||||
title: '广播',
|
||||
id: 0,
|
||||
title: '其他中心',
|
||||
icon: '/static/logo.png'
|
||||
},
|
||||
{
|
||||
id: 71,
|
||||
title: '公告',
|
||||
id: 1,
|
||||
title: '其他中心',
|
||||
icon: '/static/logo.png'
|
||||
},
|
||||
{
|
||||
id: 72,
|
||||
title: '信息发布',
|
||||
id: 2,
|
||||
title: '其他中心',
|
||||
icon: '/static/logo.png'
|
||||
}
|
||||
]
|
||||
@ -222,9 +228,10 @@
|
||||
])
|
||||
|
||||
onMounted(async () => {
|
||||
systemInfo.value = await $basic.getSystemInfo()
|
||||
const tokenStorage: string = uni.getStorageSync('token')
|
||||
if (tokenStorage) {
|
||||
const result: boolean = await $user.getUserInfo()
|
||||
const result: Result = await $user.getUserInfo()
|
||||
if (result.code === Result.Success.code) {
|
||||
console.log('获取用户信息成功')
|
||||
} else {
|
||||
@ -233,40 +240,21 @@
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const toLogin = () => {
|
||||
const clickItem = item => {
|
||||
console.log(item)
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
await $user.logout()
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
|
||||
const toNotice = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/info-publish/notice'
|
||||
})
|
||||
}
|
||||
|
||||
const toInfoPublish = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/info-publish/info-publish'
|
||||
})
|
||||
}
|
||||
|
||||
const clickItem = item => {
|
||||
console.log(item)
|
||||
if (item.id === 71) {
|
||||
toNotice()
|
||||
}
|
||||
if (item.id === 72) {
|
||||
toInfoPublish()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background: #f3f5fa;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
style: {
|
||||
navigationStyle: 'custom',
|
||||
disableScroll: true
|
||||
}
|
||||
},
|
||||
needLogin: false
|
||||
}
|
||||
</route>
|
||||
<template>
|
||||
@ -11,9 +12,9 @@
|
||||
<TopNavigation v-if="systemInfo && systemInfo?.uniPlatform === 'app'"></TopNavigation>
|
||||
<swiper
|
||||
v-if="systemInfo"
|
||||
:circular="true"
|
||||
circular="true"
|
||||
:current="index"
|
||||
:disable-touch="true"
|
||||
disable-touch="true"
|
||||
:style="{
|
||||
height: 'calc(100vh - ' + (systemInfo.safeAreaInsets?.top + 48) + 'px)'
|
||||
}"
|
||||
@ -155,8 +156,9 @@
|
||||
PasswordLoginRequest,
|
||||
UserGetCodeRequest
|
||||
} from '@/service/user'
|
||||
import { AccountChannel, CodeType, IResData, PlatId } from '@/typings'
|
||||
import { AccountChannel, CodeType, PlatId } from '@/typings'
|
||||
import { Result } from '@/constants/result'
|
||||
import GetSystemInfoResult = UniNamespace.GetSystemInfoResult
|
||||
|
||||
const $basic = useBasicStore()
|
||||
const $user = useUserStore()
|
||||
@ -250,7 +252,7 @@
|
||||
mask: true
|
||||
})
|
||||
try {
|
||||
const result: IResData = await getCodeApi<UserGetCodeRequest>({
|
||||
const result = await getCodeApi<UserGetCodeRequest>({
|
||||
account: phone.value,
|
||||
channel: AccountChannel.phone,
|
||||
codeType: CodeType.login
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
style: {
|
||||
navigationStyle: 'custom',
|
||||
disableScroll: true
|
||||
}
|
||||
},
|
||||
needLogin: false
|
||||
}
|
||||
</route>
|
||||
<template>
|
||||
@ -25,7 +26,7 @@
|
||||
@change="codeChange"
|
||||
use-suffix-slot
|
||||
>
|
||||
<template #suffix>
|
||||
<template v-slot:suffix>
|
||||
<view v-if="countDown > 0" class="text-4 custom-color-grey">
|
||||
{{ countDown }}s后重新获取
|
||||
</view>
|
||||
@ -78,7 +79,7 @@
|
||||
import { codeRegExp, passwordRegExp } from '@/constants/regular-expressions'
|
||||
import { getCodeApi, resetPasswordApi, UserGetCodeRequest } from '@/service/user'
|
||||
import { Result } from '@/constants/result'
|
||||
import { AccountChannel, CodeType, IResData } from '@/typings'
|
||||
import { AccountChannel, CodeType } from '@/typings'
|
||||
|
||||
const phone = ref<string>('')
|
||||
const code = ref<string>('')
|
||||
@ -108,7 +109,7 @@
|
||||
mask: true
|
||||
})
|
||||
try {
|
||||
const result: IResData = await getCodeApi<UserGetCodeRequest>({
|
||||
const result = await getCodeApi<UserGetCodeRequest>({
|
||||
account: phone.value,
|
||||
channel: AccountChannel.phone,
|
||||
codeType: CodeType.reset
|
||||
|
||||
@ -1,18 +1,5 @@
|
||||
// @import './iconfont.css';
|
||||
|
||||
.test {
|
||||
// 可以通过 @apply 多个样式封装整体样式
|
||||
@apply mt-4 ml-4;
|
||||
|
||||
padding-top: 4px;
|
||||
color: red;
|
||||
}
|
||||
|
||||
:root,
|
||||
page {
|
||||
// 修改按主题色
|
||||
// --wot-color-theme: #37c2bc;
|
||||
|
||||
// 修改按钮背景色
|
||||
// --wot-button-primary-bg-color: green;
|
||||
background: #f3f5fa;
|
||||
--wot-color-theme: #255cf7;
|
||||
}
|
||||
|
||||
@ -78,23 +78,21 @@ export const getUrlObj = (url: string) => {
|
||||
* 如果没有传 key,则表示所有的pages,如果传递了 key, 则表示通过 key 过滤
|
||||
*/
|
||||
export const getAllPages = (key = 'needLogin') => {
|
||||
// 这里处理主包
|
||||
const mainPages = [
|
||||
...pages
|
||||
.filter(page => !key || page[key])
|
||||
.filter(page => !key || page[key] !== false)
|
||||
.map(page => ({
|
||||
...page,
|
||||
path: `/${page.path}`
|
||||
}))
|
||||
]
|
||||
// 这里处理分包
|
||||
|
||||
const subPages: any[] = []
|
||||
subPackages.forEach(subPageObj => {
|
||||
// console.log(subPageObj)
|
||||
const { root } = subPageObj
|
||||
|
||||
subPageObj.pages
|
||||
.filter(page => !key || page[key])
|
||||
.filter(page => !key || page[key] !== false)
|
||||
.forEach((page: { path: string } & Record<string, any>) => {
|
||||
subPages.push({
|
||||
...page,
|
||||
@ -102,9 +100,7 @@ export const getAllPages = (key = 'needLogin') => {
|
||||
})
|
||||
})
|
||||
})
|
||||
const result = [...mainPages, ...subPages]
|
||||
// console.log(`getAllPages by ${key} result: `, result)
|
||||
return result
|
||||
return [...mainPages, ...subPages]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user