fix: 修改代码格式

This commit is contained in:
范鹏 2025-01-03 18:14:33 +08:00
parent b83de41177
commit 9029e334bf
8 changed files with 62 additions and 54 deletions

View File

@ -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)
}
}

View File

@ -68,7 +68,8 @@
"style": {
"navigationStyle": "custom",
"disableScroll": true
}
},
"needLogin": false
},
{
"path": "pages/get-code/get-code",

View File

@ -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()

View File

@ -33,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'
@ -55,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

View File

@ -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>>([
{
@ -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,22 +240,21 @@
icon: 'none'
})
}
} else {
uni.navigateTo({
url: '/pages/login/login'
})
}
})
const toLogin = () => {
uni.navigateTo({
url: '/pages/login/login'
})
}
const clickItem = item => {
console.log(item)
}
</script>
<style lang="scss">
page {
background: #f3f5fa;
const logout = async () => {
await $user.logout()
uni.navigateTo({
url: '/pages/login/login'
})
}
</style>
</script>

View File

@ -12,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)'
}"
@ -156,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()
@ -251,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

View File

@ -26,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>
@ -79,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>('')
@ -109,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

View File

@ -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;
}