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 { export class Result {
static codes = { static codes = {
Success: 0, Success: 0 as const,
Fail: -1, Fail: -1 as const,
NotMore: -2, NotMore: -2 as const,
PaySuccessful: 10003 PaySuccessful: 10003 as const
} }
static resultsMap = new Map([ static resultsMap = new Map<ResultCode, ResultData>([
[Result.codes.Success, { message: '成功', data: {} }], [Result.codes.Success, { message: '成功', data: {} }],
[Result.codes.Fail, { message: '网络加载失败', data: {} }], [Result.codes.Fail, { message: '网络加载失败', data: {} }],
[Result.codes.NotMore, { message: '没有更多', data: {} }], [Result.codes.NotMore, { message: '没有更多', data: {} }],
[Result.codes.PaySuccessful, { 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) const result = Result.resultsMap.get(code)
if (result) { if (result) {
this.code = code this.code = code
@ -27,22 +38,22 @@ export class Result {
} }
// 成功 // 成功
static get Success() { static get Success(): Result {
return new Result(Result.codes.Success) return new Result(Result.codes.Success)
} }
// 失败(默认错误) // 失败(默认错误)
static get Fail() { static get Fail(): Result {
return new Result(Result.codes.Fail) return new Result(Result.codes.Fail)
} }
// 没有更多 // 没有更多
static get NotMore() { static get NotMore(): Result {
return new Result(Result.codes.NotMore) return new Result(Result.codes.NotMore)
} }
// 支付成功 // 支付成功
static get PaySuccessful() { static get PaySuccessful(): Result {
return new Result(Result.codes.PaySuccessful) return new Result(Result.codes.PaySuccessful)
} }
} }

View File

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

View File

@ -3,7 +3,8 @@
style: { style: {
navigationStyle: 'custom', navigationStyle: 'custom',
disableScroll: true disableScroll: true
} },
needLogin: false
} }
</route> </route>
<template> <template>
@ -42,6 +43,7 @@
import { PlatId } from '@/typings' import { PlatId } from '@/typings'
import { Result } from '@/constants/result' import { Result } from '@/constants/result'
import { useBasicStore, useUserStore } from '@/store' import { useBasicStore, useUserStore } from '@/store'
import GetSystemInfoResult = UniNamespace.GetSystemInfoResult
const $basic = useBasicStore() const $basic = useBasicStore()
const $user = useUserStore() const $user = useUserStore()

View File

@ -33,7 +33,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { phoneRegExp } from '@/constants/regular-expressions' import { phoneRegExp } from '@/constants/regular-expressions'
import { AccountChannel, CodeType, IResData } from '@/typings' import { AccountChannel, CodeType } from '@/typings'
import { getCodeApi, UserGetCodeRequest } from '@/service/user' import { getCodeApi, UserGetCodeRequest } from '@/service/user'
import { Result } from '@/constants/result' import { Result } from '@/constants/result'
@ -55,7 +55,7 @@
mask: true mask: true
}) })
try { try {
const result: IResData = await getCodeApi<UserGetCodeRequest>({ const result = await getCodeApi<UserGetCodeRequest>({
account: phone.value, account: phone.value,
channel: AccountChannel.phone, channel: AccountChannel.phone,
codeType: CodeType.reset codeType: CodeType.reset

View File

@ -7,23 +7,29 @@
} }
</route> </route>
<template> <template>
<view class="custom-bg-default"> <view v-if="systemInfo" :style="{ marginTop: systemInfo.safeAreaInsets?.top + 'px' }">
<view v-if="$user.loginStatus"> <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> <CustomTab class="mt-10" :list="featuresList" @clickItem="clickItem"></CustomTab>
<button class="mt-12" @click="$user.logout">退出登录</button> <button class="mt-12" @click="logout">退出登录</button>
</view>
<view v-else>
<button class="mt-12" @click="toLogin">去登录</button>
</view> </view>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import CustomTab from '@/pages/home/CustomTab.vue' import CustomTab from '@/pages/home/CustomTab.vue'
import { useUserStore } from '@/store' import { useBasicStore, useUserStore } from '@/store'
import { Result } from '@/constants/result' import { Result } from '@/constants/result'
import { HomeTab, TabBarItem } from '@/typings'
const $user = useUserStore() const $user = useUserStore()
const $basic = useBasicStore()
const systemInfo = ref(null)
const list = ref<Array<TabBarItem>>([ const list = ref<Array<TabBarItem>>([
{ {
@ -222,9 +228,10 @@
]) ])
onMounted(async () => { onMounted(async () => {
systemInfo.value = await $basic.getSystemInfo()
const tokenStorage: string = uni.getStorageSync('token') const tokenStorage: string = uni.getStorageSync('token')
if (tokenStorage) { if (tokenStorage) {
const result: boolean = await $user.getUserInfo() const result: Result = await $user.getUserInfo()
if (result.code === Result.Success.code) { if (result.code === Result.Success.code) {
console.log('获取用户信息成功') console.log('获取用户信息成功')
} else { } else {
@ -233,22 +240,21 @@
icon: 'none' icon: 'none'
}) })
} }
} else {
uni.navigateTo({
url: '/pages/login/login'
})
} }
}) })
const toLogin = () => {
uni.navigateTo({
url: '/pages/login/login'
})
}
const clickItem = item => { const clickItem = item => {
console.log(item) console.log(item)
} }
</script>
<style lang="scss"> const logout = async () => {
page { await $user.logout()
background: #f3f5fa; uni.navigateTo({
url: '/pages/login/login'
})
} }
</style> </script>

View File

@ -12,9 +12,9 @@
<TopNavigation v-if="systemInfo && systemInfo?.uniPlatform === 'app'"></TopNavigation> <TopNavigation v-if="systemInfo && systemInfo?.uniPlatform === 'app'"></TopNavigation>
<swiper <swiper
v-if="systemInfo" v-if="systemInfo"
:circular="true" circular="true"
:current="index" :current="index"
:disable-touch="true" disable-touch="true"
:style="{ :style="{
height: 'calc(100vh - ' + (systemInfo.safeAreaInsets?.top + 48) + 'px)' height: 'calc(100vh - ' + (systemInfo.safeAreaInsets?.top + 48) + 'px)'
}" }"
@ -156,8 +156,9 @@
PasswordLoginRequest, PasswordLoginRequest,
UserGetCodeRequest UserGetCodeRequest
} from '@/service/user' } from '@/service/user'
import { AccountChannel, CodeType, IResData, PlatId } from '@/typings' import { AccountChannel, CodeType, PlatId } from '@/typings'
import { Result } from '@/constants/result' import { Result } from '@/constants/result'
import GetSystemInfoResult = UniNamespace.GetSystemInfoResult
const $basic = useBasicStore() const $basic = useBasicStore()
const $user = useUserStore() const $user = useUserStore()
@ -251,7 +252,7 @@
mask: true mask: true
}) })
try { try {
const result: IResData = await getCodeApi<UserGetCodeRequest>({ const result = await getCodeApi<UserGetCodeRequest>({
account: phone.value, account: phone.value,
channel: AccountChannel.phone, channel: AccountChannel.phone,
codeType: CodeType.login codeType: CodeType.login

View File

@ -26,7 +26,7 @@
@change="codeChange" @change="codeChange"
use-suffix-slot use-suffix-slot
> >
<template #suffix> <template v-slot:suffix>
<view v-if="countDown > 0" class="text-4 custom-color-grey"> <view v-if="countDown > 0" class="text-4 custom-color-grey">
{{ countDown }}s后重新获取 {{ countDown }}s后重新获取
</view> </view>
@ -79,7 +79,7 @@
import { codeRegExp, passwordRegExp } from '@/constants/regular-expressions' import { codeRegExp, passwordRegExp } from '@/constants/regular-expressions'
import { getCodeApi, resetPasswordApi, UserGetCodeRequest } from '@/service/user' import { getCodeApi, resetPasswordApi, UserGetCodeRequest } from '@/service/user'
import { Result } from '@/constants/result' import { Result } from '@/constants/result'
import { AccountChannel, CodeType, IResData } from '@/typings' import { AccountChannel, CodeType } from '@/typings'
const phone = ref<string>('') const phone = ref<string>('')
const code = ref<string>('') const code = ref<string>('')
@ -109,7 +109,7 @@
mask: true mask: true
}) })
try { try {
const result: IResData = await getCodeApi<UserGetCodeRequest>({ const result = await getCodeApi<UserGetCodeRequest>({
account: phone.value, account: phone.value,
channel: AccountChannel.phone, channel: AccountChannel.phone,
codeType: CodeType.reset 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, :root,
page { page {
// 修改按主题色 background: #f3f5fa;
// --wot-color-theme: #37c2bc; --wot-color-theme: #255cf7;
// 修改按钮背景色
// --wot-button-primary-bg-color: green;
} }