初始化
This commit is contained in:
82
pages/merchant/index.vue
Normal file
82
pages/merchant/index.vue
Normal file
@@ -0,0 +1,82 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type {ApiResult} from "~/api";
|
||||
import {useServerRequest} from "~/composables/useServerRequest";
|
||||
import {useConfigInfo, useForm, useToken, useWebsite} from "~/composables/configState";
|
||||
import type {BreadcrumbItem} from "~/types/global";
|
||||
import type {Navigation} from "~/api/cms/navigation/model";
|
||||
import {getIdBySpm} from "~/utils/common";
|
||||
|
||||
// 引入状态管理
|
||||
const route = useRoute();
|
||||
const user = useUser();
|
||||
const layout = ref<any>();
|
||||
const config = useConfigInfo();
|
||||
const token = useToken();
|
||||
const form = useForm();
|
||||
const breadcrumb = ref<BreadcrumbItem>();
|
||||
|
||||
// 请求数据
|
||||
const reload = async () => {
|
||||
|
||||
// 存在spm(优先级高)
|
||||
const {data: nav} = await useServerRequest<ApiResult<Navigation>>('/cms/cms-navigation/' + getIdBySpm(5))
|
||||
if (nav.value?.data) {
|
||||
form.value = nav.value.data
|
||||
} else {
|
||||
const {data: nav} = await useServerRequest<ApiResult<Navigation>>('/cms/cms-navigation/getNavigationByPath', {query: {path: route.path}})
|
||||
if (nav.value?.data) {
|
||||
form.value = nav.value?.data;
|
||||
}
|
||||
}
|
||||
// 页面布局
|
||||
if (form.value?.layout) {
|
||||
layout.value = JSON.parse(form.value?.layout)
|
||||
}
|
||||
|
||||
// 未登录状态(是否强制登录)
|
||||
if (!token.value || token.value == '') {
|
||||
if (config.value.MustLogin) {
|
||||
navigateTo('/passport/login');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 判断是否开发者身份
|
||||
if(!user.value?.merchantId){
|
||||
navigateTo('/user/auth');
|
||||
return false;
|
||||
}
|
||||
// 开发者身份者跳转控制台
|
||||
if(user.value.merchantId){
|
||||
console.log('已认证未开发者>')
|
||||
}
|
||||
|
||||
// seo
|
||||
useHead({
|
||||
title: `现代Web应用开发(Vue)框架 · WEBSOFT`,
|
||||
meta: [{name: form.value.design?.keywords, content: form.value.design?.description}],
|
||||
bodyAttrs: {
|
||||
class: "page-container",
|
||||
},
|
||||
script: [
|
||||
{
|
||||
children: `console.log(${JSON.stringify(form.value)})`,
|
||||
},
|
||||
],
|
||||
});
|
||||
// 面包屑
|
||||
breadcrumb.value = form.value
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
(path) => {
|
||||
console.log(path, '=>Path')
|
||||
|
||||
reload();
|
||||
},
|
||||
{immediate: true}
|
||||
);
|
||||
</script>
|
||||
Reference in New Issue
Block a user