style-格式化代码

This commit is contained in:
Huang 2023-02-20 15:14:14 +08:00
parent ff12419ce5
commit 8ff3ca01a0
55 changed files with 1535 additions and 1669 deletions

View File

@ -1,25 +1,25 @@
<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { removeInterceptor, setupInterceptors } from '@/utils/interceptors';
import { useRouterStore } from '@/state/modules/router';
onLaunch(() => {
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { removeInterceptor, setupInterceptors } from '@/utils/interceptors';
import { useRouterStore } from '@/state/modules/router';
onLaunch(() => {
console.log('App Launch');
removeInterceptor();
setupInterceptors();
const appStore = useRouterStore();
appStore.initialize();
});
onShow(() => {
});
onShow(() => {
const authStore = useAuthStore();
authStore.initToken();
console.log('App Show');
});
onHide(() => {
});
onHide(() => {
console.log('App Hide');
});
});
</script>
<style lang="scss">
@import '@/assets/main.scss';
@import '@/assets/main.scss';
</style>

View File

@ -1,29 +1,29 @@
{
"version" : "1",
"prompt" : "template",
"title" : "服务协议和隐私政策",
"message" : "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href=\"\">《服务协议》</a>和<a href=\"\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
"buttonAccept" : "同意并接受",
"buttonRefuse" : "暂不同意",
"version": "1",
"prompt": "template",
"title": "服务协议和隐私政策",
"message": "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href=\"\">《服务协议》</a>和<a href=\"\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
"buttonAccept": "同意并接受",
"buttonRefuse": "暂不同意",
// HX 3.4.13system 使webview 使uni-appweb
"hrefLoader" : "default",
"second" : {
"title" : "确认提示",
"message" : "  进入应用前,你需先同意<a href=\"\">《服务协议》</a>和<a href=\"\">《隐私政策》</a>,否则将退出应用。",
"buttonAccept" : "同意并继续",
"buttonRefuse" : "退出应用"
"hrefLoader": "default",
"second": {
"title": "确认提示",
"message": "  进入应用前,你需先同意<a href=\"\">《服务协议》</a>和<a href=\"\">《隐私政策》</a>,否则将退出应用。",
"buttonAccept": "同意并继续",
"buttonRefuse": "退出应用"
},
"styles" : {
"backgroundColor" : "#00FF00",
"borderRadius" : "5px",
"title" : {
"color" : "#ff00ff"
"styles": {
"backgroundColor": "#00FF00",
"borderRadius": "5px",
"title": {
"color": "#ff00ff"
},
"buttonAccept" : {
"color" : "#ffff00"
"buttonAccept": {
"color": "#ffff00"
},
"buttonRefuse" : {
"color" : "#00ffff"
"buttonRefuse": {
"color": "#00ffff"
}
}
}

View File

@ -1,11 +1,11 @@
<script lang="ts" setup>
import { buttonProps } from '@/components/BasicButton/prpos';
import { buttonProps } from '@/components/BasicButton/prpos';
const props = defineProps(buttonProps);
const emits = defineEmits(['click']);
const click = () => {
const props = defineProps(buttonProps);
const emits = defineEmits(['click']);
const click = () => {
emits('click');
};
};
</script>
<template>
@ -15,7 +15,7 @@
</template>
<style lang="scss" scoped>
.default-btn {
.default-btn {
color: #fff;
border-width: 4rpx;
border-color: #bfdbfe;
@ -28,5 +28,5 @@
&:hover {
background-color: #3b82f6;
}
}
}
</style>

View File

@ -3,9 +3,9 @@
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent } from 'vue';
export default defineComponent({
export default defineComponent({
name: 'BasicInput',
props: {
type: {
@ -25,7 +25,7 @@
const _props = props;
return {};
},
});
});
</script>
<style lang="scss" scoped></style>

View File

@ -1,8 +1,8 @@
<script lang="ts" setup name="Iconify">
import { computed, ref, unref } from 'vue';
import { assign } from 'lodash-es';
import { computed, ref, unref } from 'vue';
import { assign } from 'lodash-es';
const props = defineProps({
const props = defineProps({
icon: {
type: String,
},
@ -12,35 +12,23 @@
color: {
type: String,
},
});
});
const iconSize = ref<string | boolean>(
props.size ? `${props.size}rpx` : false,
);
const style = computed(() => {
return assign(
unref(iconSize)
? { width: unref(iconSize), height: unref(iconSize) }
: {},
props.color ? { color: props.color } : {},
);
});
const iconSize = ref<string | boolean>(props.size ? `${props.size}rpx` : false);
const style = computed(() => {
return assign(unref(iconSize) ? { width: unref(iconSize), height: unref(iconSize) } : {}, props.color ? { color: props.color } : {});
});
const emit = defineEmits(['click']);
const onClick = () => {
const emit = defineEmits(['click']);
const onClick = () => {
emit('click');
};
};
</script>
<template>
<view
ref="elRef"
@click="onClick"
:class="['iconify', icon]"
:style="style"
></view>
<view ref="elRef" @click="onClick" :class="['iconify', icon]" :style="style"></view>
</template>
<style lang="scss" scoped>
.iconify {
.iconify {
display: inline-block;
vertical-align: middle;
height: 44rpx;
@ -50,5 +38,5 @@
cursor: pointer;
opacity: 0.8;
}
}
}
</style>

View File

@ -1,25 +1,21 @@
<script lang="ts" setup name="Navbar">
/**
/**
* 头部导航栏
* @description 所有尺寸都用px2rpx做适配
*/
import { useSystem } from '@/hooks/useSystem';
import { px2rpx } from '@/utils/uniapi';
import { computed, ref } from 'vue';
import { useRoute, useRouter } from '@/hooks/router';
import { useGlobalStyle } from '@/hooks/useGlobalStyle';
import Iconify from '@/components/Iconify/index.vue';
import { HOME_PAGE } from '@/enums/routerEnum';
import { useSystem } from '@/hooks/useSystem';
import { px2rpx } from '@/utils/uniapi';
import { computed, ref } from 'vue';
import { useRoute, useRouter } from '@/hooks/router';
import { useGlobalStyle } from '@/hooks/useGlobalStyle';
import Iconify from '@/components/Iconify/index.vue';
import { HOME_PAGE } from '@/enums/routerEnum';
const {
navigationBarBackgroundColor,
navigationBarTitleText,
navigationBarTextStyle,
} = useGlobalStyle();
const { navigationBarBackgroundColor, navigationBarTitleText, navigationBarTextStyle } = useGlobalStyle();
const { currentRoute, currentPages } = useRoute();
const { currentRoute, currentPages } = useRoute();
const props = defineProps({
const props = defineProps({
bgColor: { type: String },
title: { type: String },
titleColor: { type: String },
@ -29,55 +25,39 @@
isBackShow: { type: Boolean, default: true },
isHomeShow: { type: Boolean },
shadow: { type: Boolean, default: true },
});
});
const { statusBarHeight } = useSystem();
const statusHeight = computed(() => `${px2rpx(statusBarHeight!)}rpx`);
const defaultNavbarHeight = ref(44);
const defaultTitleSize = ref(16);
const defaultIconSize = ref(24);
const navbarHeight = computed(
() => `${px2rpx(defaultNavbarHeight.value)}rpx`,
);
const headHeight = computed(
() => `${px2rpx((statusBarHeight || 0) + defaultNavbarHeight.value)}rpx`,
);
const sideGap = computed(() => `${px2rpx(props.gap)}rpx`);
const navbarBgColor = computed(
() => props.bgColor || navigationBarBackgroundColor,
);
const navbarTitle = computed(
() =>
props.title ||
currentRoute?.style?.navigationBarTitleText ||
navigationBarTitleText,
);
const navbarTitleColor = computed(
() =>
props.titleColor ||
currentRoute?.style?.navigationBarTextStyle ||
navigationBarTextStyle,
);
const navbarTitleSize = computed(() => {
const { statusBarHeight } = useSystem();
const statusHeight = computed(() => `${px2rpx(statusBarHeight!)}rpx`);
const defaultNavbarHeight = ref(44);
const defaultTitleSize = ref(16);
const defaultIconSize = ref(24);
const navbarHeight = computed(() => `${px2rpx(defaultNavbarHeight.value)}rpx`);
const headHeight = computed(() => `${px2rpx((statusBarHeight || 0) + defaultNavbarHeight.value)}rpx`);
const sideGap = computed(() => `${px2rpx(props.gap)}rpx`);
const navbarBgColor = computed(() => props.bgColor || navigationBarBackgroundColor);
const navbarTitle = computed(() => props.title || currentRoute?.style?.navigationBarTitleText || navigationBarTitleText);
const navbarTitleColor = computed(() => props.titleColor || currentRoute?.style?.navigationBarTextStyle || navigationBarTextStyle);
const navbarTitleSize = computed(() => {
return `${px2rpx(defaultTitleSize.value) || props.titleSize}rpx`;
});
const navbarLeftIconSize = computed(() => {
});
const navbarLeftIconSize = computed(() => {
return `${px2rpx(defaultIconSize.value) || props.titleSize}`;
});
const backShow = computed(() => {
});
const backShow = computed(() => {
return currentPages.length > 1 && props.isBackShow;
});
const backHomeShow = computed(() => {
});
const backHomeShow = computed(() => {
return !currentRoute?.meta?.tabBar && props.isHomeShow;
});
});
const router = useRouter();
const onBack = () => {
const router = useRouter();
const onBack = () => {
router.back();
};
const onBackHome = () => {
};
const onBackHome = () => {
router.pushTab(HOME_PAGE);
};
};
</script>
<template>
<view class="head-wrapper">
@ -85,49 +65,25 @@
<!-- 顶部状态栏 -->
<view class="status-bar"></view>
<!-- navbar -->
<view
:class="[
'navbar-wrapper',
'_u_flex',
'_u_flex-nowrap',
'_u_justify-between',
'_u_items-center',
]"
>
<view
class="_u_flex _u_flex-nowrap _u_items-center _u_h-full _u_w3/10 _u_min-w3/10"
>
<view :class="['navbar-wrapper', '_u_flex', '_u_flex-nowrap', '_u_justify-between', '_u_items-center']">
<view class="_u_flex _u_flex-nowrap _u_items-center _u_h-full _u_w3/10 _u_min-w3/10">
<slot name="left">
<view class="_u_h-full _u_flex _u_items-center">
<template v-if="backShow">
<Iconify
@click="onBack"
:size="navbarLeftIconSize"
:color="navbarTitleColor"
icon="i-humbleicons-chevron-left"
/>
<Iconify @click="onBack" :size="navbarLeftIconSize" :color="navbarTitleColor" icon="i-humbleicons-chevron-left" />
</template>
<template v-if="backHomeShow">
<Iconify
@click="onBackHome"
:size="navbarLeftIconSize"
:color="navbarTitleColor"
icon="i-iconoir-home-simple-door"
/>
<Iconify @click="onBackHome" :size="navbarLeftIconSize" :color="navbarTitleColor" icon="i-iconoir-home-simple-door" />
</template>
</view>
</slot>
</view>
<view
class="navbar__center _u_flex _u_flex-nowrap _u_justify-center _u_items-center _u_h-full _u_w2/5 _u_min-w2/5"
>
<view class="navbar__center _u_flex _u_flex-nowrap _u_justify-center _u_items-center _u_h-full _u_w2/5 _u_min-w2/5">
<slot>
<text>{{ navbarTitle }}</text>
</slot>
</view>
<view
class="_u_flex _u_flex-nowrap _u_justify-end _u_items-center _u_h-full _u_w3/10 _u_min-w3/10"
>
<view class="_u_flex _u_flex-nowrap _u_justify-end _u_items-center _u_h-full _u_w3/10 _u_min-w3/10">
<slot name="right"></slot>
</view>
</view>
@ -137,7 +93,7 @@
</view>
</template>
<style lang="scss" scoped>
.head-wrapper {
.head-wrapper {
.page-head {
background: v-bind(navbarBgColor);
.status-bar {
@ -159,5 +115,5 @@
height: v-bind(headHeight);
min-height: v-bind(headHeight);
}
}
}
</style>

View File

@ -1,12 +1,12 @@
<script lang="ts" setup>
const props = defineProps({
const props = defineProps({
text: {
type: String,
default: 'text',
},
});
});
const text = 'TEXT: ' + props.text;
const text = 'TEXT: ' + props.text;
</script>
<template>
<view>{{ text }}</view>

View File

@ -6,12 +6,7 @@ export enum NAVIGATE_TYPE {
NAVIGATE_BACK = 'navigateBack',
}
export const NAVIGATE_TYPE_LIST = [
'navigateTo',
'redirectTo',
'reLaunch',
'switchTab',
];
export const NAVIGATE_TYPE_LIST = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];
export const HOME_PAGE = '/pages/index/index';
export const LOGIN_PAGE = '/pages/login/index';

View File

@ -5,12 +5,7 @@ const { globalStyle } = pagesJson;
*
*/
export const useGlobalStyle = () => {
const {
navigationBarTextStyle,
navigationBarTitleText,
navigationBarBackgroundColor,
backgroundColor,
} = globalStyle;
const { navigationBarTextStyle, navigationBarTitleText, navigationBarBackgroundColor, backgroundColor } = globalStyle;
return {
navigationBarTextStyle,
navigationBarTitleText,

View File

@ -78,20 +78,8 @@ export const useSystem = () => {
cacheLocation,
storage,
} = uni.getSystemInfoSync();
const {
top: safeAreaTop,
bottom: safeAreaBottom,
left: safeAreaLeft,
right: safeAreaRight,
height: safeAreaHeight,
width: safeAreaWidth,
} = safeArea!;
const {
top: safeAreaInsetsTop,
bottom: safeAreaInsetsBottom,
left: safeAreaInsetsLeft,
right: safeAreaInsetsRight,
} = safeAreaInsets!;
const { top: safeAreaTop, bottom: safeAreaBottom, left: safeAreaLeft, right: safeAreaRight, height: safeAreaHeight, width: safeAreaWidth } = safeArea!;
const { top: safeAreaInsetsTop, bottom: safeAreaInsetsBottom, left: safeAreaInsetsLeft, right: safeAreaInsetsRight } = safeAreaInsets!;
return {
deviceId,
deviceBrand,

View File

@ -1,27 +1,27 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useAuthStore } from '@/state/modules/auth';
import { useRouter } from '@/hooks/router';
import { ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useAuthStore } from '@/state/modules/auth';
import { useRouter } from '@/hooks/router';
const authStore = useAuthStore();
const isLogin = ref(false);
const router = useRouter();
onShow(() => {
const authStore = useAuthStore();
const isLogin = ref(false);
const router = useRouter();
onShow(() => {
isLogin.value = authStore.isLogin;
});
const handleJump = (url: string) => {
});
const handleJump = (url: string) => {
router.push(url);
};
};
//
const handleLoginOut = () => {
//
const handleLoginOut = () => {
authStore.loginOut().then(() => {
isLogin.value = false;
});
};
};
</script>
<template>
@ -33,25 +33,17 @@
</view>
<view class="desc">{{ isLogin ? '测试' : '未登入' }}</view>
</view>
<view class="cell"
><BasicButton @click="handleJump('/pages/log/index?id=4345&title=log')"
>log</BasicButton
></view
>
<view class="cell" v-if="isLogin"
><BasicButton @click="handleLoginOut">登出</BasicButton></view
>
<view class="cell"><BasicButton @click="handleJump('/pages/log/index?id=4345&title=log')">log</BasicButton></view>
<view class="cell" v-if="isLogin"><BasicButton @click="handleLoginOut">登出</BasicButton></view>
<view class="cell" v-else>
<BasicButton @click="handleJump('/pages/login/index')">
登入
</BasicButton>
<BasicButton @click="handleJump('/pages/login/index')"> 登入 </BasicButton>
</view>
</view>
</AppProvider>
</template>
<style lang="scss" scoped>
.container {
.container {
padding: 96rpx 24rpx;
.head-wrap {
display: flex;
@ -78,5 +70,5 @@
margin-top: 60rpx;
text-align: center;
}
}
}
</style>

View File

@ -1,12 +1,12 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from '@/hooks/router';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpList1 = () => {
const router = useRouter();
const jumpList1 = () => {
router.push('/pagesA/list/test1/index?key=words&page=1&limit=15');
};
};
</script>
<template>
@ -19,8 +19,8 @@
</template>
<style lang="scss" scoped>
.container {
.container {
padding: 128rpx 0;
text-align: center;
}
}
</style>

View File

@ -1,23 +1,23 @@
<script setup lang="ts">
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from '@/hooks/router';
import { CURRENT_PLATFORM, PLATFORMS } from '@/enums/platformEnum';
import { judgePlatform } from '@/utils/platform';
import Iconify from '@/components/Iconify/index.vue';
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
import { useRouter } from '@/hooks/router';
import { CURRENT_PLATFORM, PLATFORMS } from '@/enums/platformEnum';
import { judgePlatform } from '@/utils/platform';
import Iconify from '@/components/Iconify/index.vue';
const title = ref('uni-app vue3 ts --Vite');
const title = ref('uni-app vue3 ts --Vite');
const platform = CURRENT_PLATFORM;
const platform = CURRENT_PLATFORM;
const isVue3 = judgePlatform(PLATFORMS.VUE3);
const isVue3 = judgePlatform(PLATFORMS.VUE3);
const router = useRouter();
const handleGetStarted = () => {
const router = useRouter();
const handleGetStarted = () => {
router.pushTab('/pages/demo/index');
// router.push('/pages/log/index?id=4345&title=log');
};
};
</script>
<template>
<AppProvider>
@ -43,27 +43,27 @@
</AppProvider>
</template>
<style lang="scss">
.content {
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
}
.logo {
.logo {
height: 200rpx;
width: 200rpx;
margin: 280rpx auto 50rpx;
}
}
.text-area {
.text-area {
display: flex;
justify-content: center;
margin-bottom: 60rpx;
}
}
.title {
.title {
font-size: 36rpx;
color: #8f8f94;
}
}
</style>

View File

@ -3,11 +3,11 @@
</template>
<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { onLoad } from '@dcloudio/uni-app';
onLoad(query => {
onLoad((query) => {
console.log('log onLoad', query);
});
});
</script>
<style lang="scss" scoped></style>

View File

@ -1,25 +1,23 @@
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { Toast } from '@/utils/uniapi/prompt';
import { useRouter } from '@/hooks/router';
import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { Toast } from '@/utils/uniapi/prompt';
import { useRouter } from '@/hooks/router';
const redirect = ref<string | undefined>(undefined);
onLoad(query => {
redirect.value = query.redirect
? decodeURIComponent(query.redirect)
: undefined;
});
const redirect = ref<string | undefined>(undefined);
onLoad((query) => {
redirect.value = query.redirect ? decodeURIComponent(query.redirect) : undefined;
});
const router = useRouter();
const router = useRouter();
const form = reactive({
const form = reactive({
email: 'uni-app@test.com',
password: 'Vue3_Ts_Vite',
});
const authStore = useAuthStore();
const submit = (e: any) => {
});
const authStore = useAuthStore();
const submit = (e: any) => {
authStore.login(e.detail.value).then(() => {
Toast('登录成功', { duration: 1500 });
setTimeout(() => {
@ -30,7 +28,7 @@
router.pushTab('/pages/about/index');
}, 1500);
});
};
};
</script>
<template>
@ -40,26 +38,20 @@
<form class="form" @submit="submit">
<label class="form-item">
<view class="form-label">邮箱:</view>
<view class="form-element"
><input name="email" :value="form.email"
/></view>
<view class="form-element"><input name="email" :value="form.email" /></view>
</label>
<label class="form-item">
<view class="form-label">密码:</view>
<view class="form-element"
><input type="password" name="password" :value="form.password"
/></view>
<view class="form-element"><input type="password" name="password" :value="form.password" /></view>
</label>
<button form-type="submit" class="submit-btn" hover-class="none"
>登录</button
>
<button form-type="submit" class="submit-btn" hover-class="none">登录</button>
</form>
</view>
</view>
</template>
<style lang="scss" scoped>
.container {
.container {
margin: 0 auto;
width: 80%;
.title {
@ -95,5 +87,5 @@
}
}
}
}
}
</style>

View File

@ -1,23 +1,23 @@
<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
const go = ref<string>('');
const router = useRouter();
const redirect = ref<string>('');
onLoad(query => {
const go = ref<string>('');
const router = useRouter();
const redirect = ref<string>('');
onLoad((query) => {
go.value = query.go || '';
redirect.value = query.redirect || '';
});
});
/**
/**
* 返回首页
*/
const backHome = () => {
const backHome = () => {
router.pushTab(redirect.value);
};
};
</script>
<template>

View File

@ -1,16 +1,14 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpTest2 = () => {
const router = useRouter();
const jumpTest2 = () => {
router.push('/pagesA/list/test2/index?id=256');
};
};
</script>
<template>
<view class="_u_center"> Test1 </view>
<view class="_u_center"
><BasicButton @click="jumpTest2">Test2 </BasicButton></view
>
<view class="_u_center"><BasicButton @click="jumpTest2">Test2 </BasicButton></view>
</template>
<style scoped></style>

View File

@ -1,11 +1,11 @@
<script lang="ts" setup>
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
import BasicButton from '@/components/BasicButton/index.vue';
import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpDetail = () => {
const router = useRouter();
const jumpDetail = () => {
router.push('/pagesB/detail/index?page=1&limit=20');
};
};
</script>
<template>
<view>

View File

@ -1,3 +1,3 @@
<script lang="ts" setup></script>
<template> Detail </template>
<template>Detail</template>
<style scoped></style>

View File

@ -2,10 +2,7 @@ import { getEnvValue, getPkgVersion, isDevMode } from '@/utils/env';
// System default cache time, in seconds
export const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7;
const PREFIX =
getEnvValue<string>('VITE_APP_CACHE_PREFIX') ||
getEnvValue<string>('VITE_APP_TITLE') ||
'UNI_APP_VUE3_TS';
const PREFIX = getEnvValue<string>('VITE_APP_CACHE_PREFIX') || getEnvValue<string>('VITE_APP_TITLE') || 'UNI_APP_VUE3_TS';
export const DEFAULT_PREFIX_KEY = `${PREFIX}${getPkgVersion()}`;
// aes encryption key

View File

@ -13,7 +13,7 @@ export const useAuthStore = defineStore({
token: undefined,
}),
getters: {
getToken: state => state.token,
getToken: (state) => state.token,
isLogin: (state): boolean => !!state.token,
},
actions: {

View File

@ -22,7 +22,7 @@ export interface RouteLocationNormalized {
/* 当前页面栈的实例 */
currentPages: Page.PageInstance<AnyObject, {}>[];
/* 当前页面的实例 */
currentPage: Page.PageInstance;
currentPage: Page.PageInstance | undefined;
/* 当前页面在pages.json中的配置 */
currentRoute?: Route;
/* 当前页面的path */

View File

@ -1,10 +1,5 @@
import { createStorage, CreateStorageParams } from './storageCache';
import {
cacheCipher,
DEFAULT_CACHE_TIME,
DEFAULT_PREFIX_KEY,
enableStorageEncryption,
} from '@/settings/encryptionSetting';
import { cacheCipher, DEFAULT_CACHE_TIME, DEFAULT_PREFIX_KEY, enableStorageEncryption } from '@/settings/encryptionSetting';
const options: Partial<CreateStorageParams> = {
prefixKey: DEFAULT_PREFIX_KEY,
@ -16,11 +11,7 @@ const options: Partial<CreateStorageParams> = {
export const storage = createStorage(options);
export function setCache(
key: string,
value: any,
expire?: number | null,
): void {
export function setCache(key: string, value: any, expire?: number | null): void {
storage.set(key, value, expire);
}

View File

@ -15,7 +15,7 @@ export const createStorage = ({
timeout = null,
hasEncrypt = true,
}: Partial<CreateStorageParams> = {}) => {
if (hasEncrypt && [key.length, iv.length].some(item => item !== 16)) {
if (hasEncrypt && [key.length, iv.length].some((item) => item !== 16)) {
throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
}
@ -60,13 +60,9 @@ export const createStorage = ({
const stringData = JSON.stringify({
value,
time: Date.now(),
expire: !isNullOrUnDef(expire)
? new Date().getTime() + expire * 1000
: null,
expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
});
const stringifyValue = this.hasEncrypt
? this.encryption.encryptByAES(stringData)
: stringData;
const stringifyValue = this.hasEncrypt ? this.encryption.encryptByAES(stringData) : stringData;
uni.setStorageSync(this.getKey(key), stringifyValue);
} catch (err) {
throw new Error(`setStorageSync error: ${err}`);
@ -84,9 +80,7 @@ export const createStorage = ({
if (!val) return def;
try {
const decVal = this.hasEncrypt
? this.encryption.decryptByAES(val)
: val;
const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
const data = JSON.parse(decVal);
const { value, expire } = data;
if (isNullOrUnDef(expire) || expire < new Date().getTime()) {

View File

@ -26,7 +26,7 @@ const request = createRequest();
*
*/
request.interceptors.request.use(
options => {
(options) => {
if (options.custom?.auth) {
const authStore = useAuthStore();
if (!authStore.isLogin) {
@ -40,14 +40,14 @@ request.interceptors.request.use(
}
return options;
},
options => Promise.reject(options),
(options) => Promise.reject(options)
);
/**
*
*/
request.interceptors.response.use(
async response => {
async (response) => {
const { data: resData } = response;
const { code, message } = resData;
if (code === ResultEnum.SUCCESS) {
@ -56,10 +56,10 @@ request.interceptors.response.use(
Toast(message);
return Promise.reject(resData);
},
response =>
(response) =>
// 请求错误做点什么。可以使用async await 做异步操作
// error('Request Error!');
Promise.reject(response),
Promise.reject(response)
);
export { request };

View File

@ -8,9 +8,7 @@ import { isObject } from '@/utils/is';
export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
let key: string;
for (key in target) {
src[key] = isObject(src[key])
? deepMerge(src[key], target[key])
: (src[key] = target[key]);
src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
}
return src;
}

View File

@ -1,7 +1,4 @@
import {
routerInterceptor,
routerRemoveInterceptor,
} from '@/utils/router/interceptor';
import { routerInterceptor, routerRemoveInterceptor } from '@/utils/router/interceptor';
export function setupInterceptors() {
routerInterceptor();

View File

@ -53,12 +53,7 @@ export function isNumber(val: unknown): val is number {
}
export function isPromise<T = any>(val: unknown): val is Promise<T> {
return (
is(val, 'Promise') &&
isObject(val) &&
isFunction(val.then) &&
isFunction(val.catch)
);
return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch);
}
export function isString(val: unknown): val is string {

View File

@ -1,8 +1,4 @@
import {
HOME_PAGE,
NAVIGATE_TYPE_LIST,
NOT_FOUND_PAGE,
} from '@/enums/routerEnum';
import { HOME_PAGE, NAVIGATE_TYPE_LIST, NOT_FOUND_PAGE } from '@/enums/routerEnum';
import { useAuthStore } from '@/state/modules/auth';
import { isIgnoreAuth, jumpLogin } from '@/utils/router/constant';
@ -32,7 +28,7 @@ export function routerBeforeEach(path: string): boolean {
function addInterceptor(routerName: string) {
uni.addInterceptor(routerName, {
// 跳转前拦截
invoke: args => {
invoke: (args) => {
const flag = routerBeforeEach(args.url);
return flag ? args : false;
},
@ -64,7 +60,7 @@ function addInterceptor(routerName: string) {
*
*/
export function routerInterceptor() {
NAVIGATE_TYPE_LIST.forEach(item => {
NAVIGATE_TYPE_LIST.forEach((item) => {
addInterceptor(item);
});
}
@ -73,7 +69,7 @@ export function routerInterceptor() {
*
*/
export function routerRemoveInterceptor() {
NAVIGATE_TYPE_LIST.forEach(item => {
NAVIGATE_TYPE_LIST.forEach((item) => {
uni.removeInterceptor(item);
});
}

View File

@ -7,14 +7,14 @@ const { pages, subPackages, tabBar } = pagesJson;
// 将pages.json转换成Map对象,path为key
const pagesMap = new Map<string, Route>();
pages.forEach(page => {
pages.forEach((page) => {
pagesMap.set(page.path, page as Route);
});
if (Array.isArray(subPackages) && subPackages.length) {
subPackages.forEach(el => {
subPackages.forEach((el) => {
const rootPath = el.root;
el.pages.forEach(page => {
el.pages.forEach((page) => {
page.path = `${rootPath}/${page.path}`;
pagesMap.set(page.path, page as Route);
});
@ -24,7 +24,7 @@ if (Array.isArray(subPackages) && subPackages.length) {
if (tabBar) {
const tabBarList = tabBar.list;
if (Array.isArray(tabBarList)) {
tabBarList.forEach(el => {
tabBarList.forEach((el) => {
if (pagesMap.has(el.pagePath)) {
const page = pagesMap.get(el.pagePath);
const meta = page?.meta || {};

View File

@ -9,10 +9,10 @@ export const SetClipboardData = (data: string, showToast = true) =>
uni.setClipboardData({
data,
showToast,
success: res => {
success: (res) => {
resolve(res);
},
fail: err => {
fail: (err) => {
reject(err);
},
});
@ -25,10 +25,10 @@ export const SetClipboardData = (data: string, showToast = true) =>
export const GetClipboardData = () =>
new Promise((resolve, reject) => {
uni.getClipboardData({
success: res => {
success: (res) => {
resolve(res);
},
fail: err => {
fail: (err) => {
reject(err);
},
});

View File

@ -9,10 +9,7 @@
* @param options
* @constructor
*/
export function Toast(
title: string,
options?: Partial<UniApp.ShowToastOptions>,
) {
export function Toast(title: string, options?: Partial<UniApp.ShowToastOptions>) {
uni.showToast({
title,
duration: 1500,
@ -35,10 +32,7 @@ export function HideToast() {
* @param options
* @constructor
*/
export function Loading(
title: string,
options?: Partial<UniApp.ShowLoadingOptions>,
) {
export function Loading(title: string, options?: Partial<UniApp.ShowLoadingOptions>) {
uni.showLoading({
title,
mask: true,
@ -62,10 +56,10 @@ export function Modal(options: UniApp.ShowModalOptions) {
return new Promise((resolve, reject) => {
uni.showModal({
...options,
success: res => {
success: (res) => {
resolve(res);
},
fail: res => {
fail: (res) => {
reject(res);
},
});
@ -81,10 +75,10 @@ export function ActionSheet(options: UniApp.ShowActionSheetOptions) {
return new Promise((resolve, reject) => {
uni.showActionSheet({
...options,
success: res => {
success: (res) => {
resolve(res);
},
fail: res => {
fail: (res) => {
reject(res);
},
});