添加hash支持(页面)

This commit is contained in:
LittleBoy 2023-12-31 18:16:00 +08:00
parent 21d6bb8611
commit c41039cdb5
8 changed files with 104 additions and 31 deletions

View File

@ -3,8 +3,12 @@ import {onMounted, ref} from "vue";
import Login from "./components/login/index.vue"; import Login from "./components/login/index.vue";
import DataFields from "./components/data-fields/index.vue"; import DataFields from "./components/data-fields/index.vue";
import Product from "./components/product/index.vue";
import Field from "./components/field/index.vue";
import Result from "./components/result/index.vue";
import {MenuItem, Menu, Icon} from "view-ui-plus"; import {MenuItem, Menu, Icon} from "view-ui-plus";
import Layout from "./components/layout/index.vue" import {useHash} from "./service/router.ts";
const page_data = ref({ const page_data = ref({
showLogin: false, showLogin: false,
@ -23,27 +27,32 @@ onMounted(() => {
} }
}) })
const MENU_LIST = [ const MENU_LIST = [
{title:'药品管理',name:'products',icon:'ios-cube'}, {title: '药品管理', name: 'product', icon: 'ios-cube'},
{title:'数据项管理',name:'fields',icon:'ios-apps'}, {title: '数据项管理', name: 'field', icon: 'ios-apps'},
{title:'数据管理',name:'product_value',icon:'ios-paper'}, {title: '数据管理', name: 'product_value', icon: 'ios-paper'},
{title:'计算结果',name:'result',icon:'ios-calculator'}, {title: '计算结果', name: 'result', icon: 'ios-calculator'},
] ]
const activeMenu = ref(MENU_LIST[0].name) const hash = useHash()
const onMenuSelect = (name:string)=>activeMenu.value = name const activeMenu = ref((hash.value || MENU_LIST[0].name))
const onMenuSelect = (name: string) => {
activeMenu.value = name
window.location.hash = name
}
</script> </script>
<template> <template>
<div class="app-container"> <div class="app-container">
<Login v-if="page_data.showLogin" @login-success="onLoginSuccess"/> <Login v-if="page_data.showLogin" @login-success="onLoginSuccess"/>
<!-- <Layout />--> <!-- <Layout />-->
<div class="app-header"> <div class="app-header">
<div class="app-logo"> <div class="app-logo">
<img class="logo" src="./assets/images/logo.png" alt="" /> <img class="logo" src="./assets/images/logo.png" alt=""/>
</div> </div>
<div class="app-menu"> <div class="app-menu">
<Menu mode="horizontal" :active-name="activeMenu" @on-select="onMenuSelect"> <Menu mode="horizontal" :active-name="activeMenu" @on-select="onMenuSelect">
<MenuItem v-for="m in MENU_LIST" :key="m.name" :name="m.name"> <MenuItem v-for="m in MENU_LIST" :key="m.name" :name="m.name">
<Icon :type="m.icon" size="20" /> <Icon :type="m.icon" size="18"/>
<span>{{ m.title }}</span> <span>{{ m.title }}</span>
</MenuItem> </MenuItem>
</Menu> </Menu>
@ -51,6 +60,9 @@ const onMenuSelect = (name:string)=>activeMenu.value = name
</div> </div>
<div class="app-content"> <div class="app-content">
<DataFields v-if="activeMenu == 'product_value'"/> <DataFields v-if="activeMenu == 'product_value'"/>
<Field v-else-if="activeMenu == 'field'"/>
<Product v-else-if="activeMenu == 'product'"/>
<Result v-else/>
</div> </div>
</div> </div>
</template> </template>
@ -61,32 +73,37 @@ const onMenuSelect = (name:string)=>activeMenu.value = name
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
} }
.app-header{
.app-header {
display: flex; display: flex;
align-items: center; align-items: center;
border-bottom: solid 1px #dcdee2; border-bottom: solid 1px #dcdee2;
box-shadow: 0 0 5px rgba(0,0,0,0.2); box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
position: sticky; position: sticky;
top: 0; top: 0;
padding: 0 50px; padding: 0 50px;
justify-content: space-between; justify-content: space-between;
} }
.app-menu{
.ivu-menu{ .app-menu {
&:after{ .ivu-menu {
&:after {
display: none; display: none;
} }
} }
} }
.app-content{
.app-content {
padding: 20px 50px; padding: 20px 50px;
} }
.app-logo{
.app-logo {
padding: 10px; padding: 10px;
margin-right: 50px; margin-right: 50px;
display: flex; display: flex;
align-items: center; align-items: center;
} }
body { body {
background: #fff; background: #fff;
color: #000; color: #000;

View File

@ -0,0 +1,11 @@
<script setup lang="ts">
</script>
<template>
<h1>field</h1>
</template>
<style scoped lang="scss">
</style>

View File

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import DataFields from "@/components/data-fields/index.vue"; import DataFields from "../../components/data-fields/index.vue";
import {Breadcrumb, BreadcrumbItem, Card, Content, Header, Icon, Layout, Menu, MenuItem} from "view-ui-plus"; import {Breadcrumb, BreadcrumbItem, Card, Content, Header, Icon, Layout, Menu, MenuItem} from "view-ui-plus";
import {ref} from "vue"; import {ref} from "vue";

View File

@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import {Login as LoginForm, UserName, Password, Submit, Message} from 'view-ui-plus'; import {Login, UserName, Password, Submit, Message} from 'view-ui-plus';
import {onMounted} from "vue";
type LoginModel = { type LoginModel = {
username: string; username: string;
@ -10,7 +9,8 @@ type LoginModel = {
const emits = defineEmits<{ const emits = defineEmits<{
(e: 'loginSuccess'): void (e: 'loginSuccess'): void
}>() }>()
const handleSubmit = (valid: true, params: LoginModel) => { const handleSubmit = (...e:any) => {
const [valid,params] = e as [valid: true, params: LoginModel];
if (valid) { if (valid) {
if (params.username == 'admin' && params.password == 'admin') { if (params.username == 'admin' && params.password == 'admin') {
emits('loginSuccess') emits('loginSuccess')
@ -29,13 +29,13 @@ const handleSubmit = (valid: true, params: LoginModel) => {
<img src="../../assets/images/logo.png" alt=""> <img src="../../assets/images/logo.png" alt="">
</div> </div>
<p class="desc">营养与健康数据管理处理平台</p> <p class="desc">营养与健康数据管理处理平台</p>
<LoginForm @on-submit="handleSubmit"> <Login @on-submit="handleSubmit">
<UserName name="username" enterkeyhint/> <UserName name="username" enter-to-submit/>
<Password name="password" enterkeyhint/> <Password name="password" enter-to-submit/>
<div class="submit"> <div class="submit">
<Submit/> <Submit/>
</div> </div>
</LoginForm> </Login>
</div> </div>
</div> </div>
</template> </template>

View File

@ -0,0 +1,11 @@
<script setup lang="ts">
</script>
<template>
<h1>product</h1>
</template>
<style scoped lang="scss">
</style>

View File

@ -0,0 +1,11 @@
<script setup lang="ts">
</script>
<template>
<h1>result</h1>
</template>
<style scoped lang="scss">
</style>

22
src/service/router.ts Normal file
View File

@ -0,0 +1,22 @@
import {onMounted, onUnmounted, ref} from "vue";
function getHash() {
const hash = window.location.hash
return hash.length > 0 ? hash.slice(1) : '';
}
export const useHash = () => {
const hash = ref<string>(getHash())
const onHashChange = () => {
hash.value = getHash()
}
onMounted(() => {
window.addEventListener('hashchange', onHashChange, false)
})
onUnmounted(() => {
window.removeEventListener('hashchange', onHashChange, false)
})
return hash
}

View File

@ -15,16 +15,17 @@ export default defineConfig({
if (id.includes('view-ui-plus')) { if (id.includes('view-ui-plus')) {
return 'view-ui' return 'view-ui'
} }
if (id.includes('vue')) { // if (id.includes('vue')) {
return 'vue' // return 'vue'
} // }
if (id.includes('node_modules')) { // if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString(); // return id.toString().split('node_modules/')[1].split('/')[0].toString();
} // }
} }
} }
}, },
}, },
base: './',
// resolve:{ // resolve:{
// alias:{ // alias:{
// '@': path.resolve(__dirname,"./src") // '@': path.resolve(__dirname,"./src")