Browse Source

搭建项目

master
邓宏 2 years ago
parent
commit
e6c4ac89dd
  1. 88
      src/components/HelloWorld.vue
  2. 19
      src/layout/component/appMain.vue
  3. 2
      src/layout/component/index.js
  4. 26
      src/layout/component/sidebar/index.vue
  5. 15
      src/layout/component/sidebar/item.vue
  6. 63
      src/layout/component/sidebar/sidebarItem.vue
  7. 29
      src/layout/index.vue
  8. 23
      src/router/index.js
  9. 30
      src/view/demo.vue
  10. 33
      src/view/home.vue
  11. 10
      src/views/home.vue

88
src/components/HelloWorld.vue

@ -1,88 +0,0 @@
<style lang='less' scoped>
a {
color: #42b983;
background: v-bind(color);
}
.demo{
color:blue;
span{
font-weight: bold;
text-decoration: initial;
font-size:40px;
}
}
</style>
<style lang="less" module="cssName">
.demo{
color:red;
span{
font-weight: bold;
text-decoration: initial;
font-size:40px;
}
}
</style>
<template>
<h1 v-bind="$attrs">{{ msg }}</h1>
<slot/>
<slot name="demo"/>
<p v-my-directive>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>
<!-- v-memo 类似于 v-one 数组内的值变换时会更新 -->
<p v-memo="[b]">
{{count}}
</p>
<div class="demo">1-<span>2</span></div>
<button type="button" @click="count++">count is: {{ count }}</button>
<p :class="cssName.demo">
<span>Edit</span>{{foo}}
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
--{{num}}
<hello-world v-if="num>0" :num="num-1" msg="-----msg----"/>
</template>
<script setup>
import { ref, useAttrs, useSlots, useCssVars, inject, defineExpose } from 'vue'
console.log(inject("store"),'---------------store--------')
console.log(useAttrs(),'-------useAttrs-------')
console.log(useSlots(),'---------useSlots--')
defineProps({
msg: String,
num: Number
})
useCssVars(e=>{
console.log(e,"-----------ctx----")
})
const emit=defineEmits(['close'])
console.log(emit,'-------emit-----------')
const count = ref(0)
const color="#342e91"
const b=ref('ddd')
window.b=b
defineExpose({ // 使
count
})
const vMyDirective={
//
// attribute
created(el, binding, vnode) {},
//
beforeMount() {},
//
mounted() {},
// VNode
beforeUpdate() {},
// VNode VNode
updated() {},
//
beforeUnmount() {},
//
unmounted() {}
}
</script>

19
src/layout/component/appMain.vue

@ -1,19 +0,0 @@
<style lang="less" scoped>
</style>
<template>
<router-view v-slot="{ Component }">
<transition name="fade-transform" mode="out-in">
<keep-alive :include="cachedViews">
<component :is="Component" v-if="cached" :key="$route.path"/>
</keep-alive>
</transition>
<component :is="Component" :key="$route.path" v-if="!cached"/>
</router-view>
</template>
<script setup>
import { shallowRef } from 'vue'
var cachedViews=shallowRef(['demo'])
var cached=true
</script>

2
src/layout/component/index.js

@ -1,2 +0,0 @@
export {default as sidebar} from './sidebar/index.vue'
export {default as appMain} from './appMain.vue'

26
src/layout/component/sidebar/index.vue

@ -1,26 +0,0 @@
<style lang="less" scoped>
.el-menu{
border-right:none;
}
</style>
<template>
<el-scrollbar>
<el-menu
:default-active="path"
background-color="#001529"
text-color="#bfcbd9"
:unique-opened="true"
active-text-color="#409EFF"
router>
<sidebar-item v-for="(route,k) in menu" :key="k" :item="route" :base-path="route.path"/>
</el-menu>
</el-scrollbar>
</template>
<script setup>
import { inject } from 'vue'
import sidebarItem from "./sidebarItem.vue"
import {useRoute} from 'vue-router'
import {menu} from "@/router"
var {path} = inject("route")
</script>

15
src/layout/component/sidebar/item.vue

@ -1,15 +0,0 @@
<style lang="less" scoped>
.svg-icon{
margin-right:5px;
}
</style>
<template>
<svg-icon v-if="icon" :name="icon"/>
<span v-if="title">{{title}}</span>
</template>
<script setup>
var {icon, title}=defineProps({
icon:String,
title:String,
})
</script>

63
src/layout/component/sidebar/sidebarItem.vue

@ -1,63 +0,0 @@
<style lang="less" scoped>
</style>
<template>
<template v-if="!props.item?.meta?.hidden">
<template v-if="hasOneShowingChild(props.item.children, props.item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren) && !props.item.alwaysShow">
<el-menu-item :index=" /^\//.test(onlyOneChild.path)?onlyOneChild.path:basePath " >
<item :icon="onlyOneChild.meta?.icon||''" :title="onlyOneChild.meta?.title||''"/>
</el-menu-item>
</template>
<el-sub-menu v-else ref="subMenu" :index="resolvePath(props.item.path)">
<template #title>
<item v-if="props.item.meta" :icon="props.item.meta?.icon||''" :title="props.item.meta?.title||''"/>
</template>
<sidebar-item
v-for="(child,k) in props.item.children"
:key="k"
:item="child"
:base-path="resolvePath(child.path)"/>
</el-sub-menu>
</template>
</template>
<script setup>
import { inject, onMounted, shallowRef } from 'vue'
import item from './item.vue'
var props=defineProps({
item:Object,
basePath:String,
})
var {commit} = inject("store")
var onlyOneChild=shallowRef({})
function hasOneShowingChild(children=[], parent){
var showingChildren=children.filter(i=>{
if(i?.meta?.hidden)return false;
else{
onlyOneChild.value=i;
return true
}
})
if(showingChildren.length==1)return true;
if(showingChildren.length==0){
onlyOneChild.value={ path:'',noShowingChildren:true, ...parent}
return true;
}
return false;
}
function resolvePath(routePath){
if(/^\//.test(routePath))return routePath;
return `${props.basePath}/${routePath}`.replace(/\/+/g,'/')
}
onMounted(async ()=>{
commit('data/setMenu',{
key: resolvePath(props.basePath),
item:{
name: props.item.name,
parentPath: props.item?.meta?.parentPath,
}
})
})
</script>

29
src/layout/index.vue

@ -1,29 +0,0 @@
<style lang="less" scoped>
.wrapper{
display:flex;
height: 100%;
&>.sidebar-container{
flex-shrink: 0;
width: 210px !important;
background-color: #001529;
z-index:100;
.el-scrollbar__view{
height:100%;
}
}
&>.main-container{
flex-grow: 1;
}
}
</style>
<template>
<div class="wrapper">
<sidebar class="sidebar-container"/>
<div class="main-container">
<app-main/>
</div>
</div>
</template>
<script setup>
import {sidebar, appMain} from './component'
</script>

23
src/router/index.js

@ -1,22 +1,12 @@
import { createRouter, createWebHashHistory } from "vue-router";
import layout from '@/layout/index.vue'
import store from '@/store'
const routes=[]
export const menu = [
{
path:"/",
name:"home",
component:layout,
redirect:"/home",
meta:{
title:"测试页面",
icon:"set",
},
children:[
setPath({path:"home",name:"home",meta:{title:"首页", icon:"set"},page:import("@/view/home.vue")}),
setPath({path:"demo",name:"demo",meta:{title:"demo", icon:"set"},page:import("@/view/demo.vue")}),
]
component:()=>import("@/views/home.vue"),
children:[]
},
];
const router = createRouter({
@ -24,13 +14,4 @@ const router = createRouter({
routes: routes.concat(menu),
});
function setPath(val){
return{
path:val.path,
name:val.name,
meta:val.meta||{},
component:()=>val.page.then(e=>({...e.default,name:val.name}))
}
}
export default router;

30
src/view/demo.vue

@ -1,30 +0,0 @@
<style lang="less" scoped>
</style>
<template>
<h1 @click="$router.go(-1)">demo page</h1>
<vue3VideoPlay
width="800px"
title="冰河世纪"
v-bind="options"
:autoPlay="false"/>
</template>
<script setup>
import { nextTick, onActivated, onMounted, reactive } from "vue"
console.log(">>>>>>>>>>>>---------demo---------setup---------")
onActivated(()=>{
console.log(">>>>>>>>>>>>>------demo-----------activated-------")
})
var options=reactive({
// src:"https://open.ys7.com/v3/openlive/J91439318_1_1.m3u8?expire=1700465231&id=516273656091906048&t=92d4bc07e37fa42eb4e315cfa35cebf2447a2f1a5fb95517b611a37a19c731d0&ev=100",
src:"http://223.110.241.204:6610/gitv/live1/G_CCTV-1-CQ/G_CCTV-1-CQ/1.m3u8",
type:"m3u8",
poster: '', //
color: "#409eff", //
})
onMounted(()=>{
})
</script>

33
src/view/home.vue

@ -1,33 +0,0 @@
<style lang="less" scoped>
.container{
text-align: center;
}
</style>
<template>
<div class="container">
<div @click="$router.push({path:'/demo'})">demo</div>
svg-icon:<svg-icon name="car" style="font-size:20px;"/>
<img alt="Vue logo" src="~@/assets/img/logo.png" />
<img :src="require('@/assets/img/logo.png')"/>
<hello-world msg="Hello Vue 3 + Vite" :num='1' style="color:red;" class="hello">
<div class="a">111</div>
<template #demo>
<div>{{foo}}</div>
</template>
</hello-world>
<dInput v-model.digit="value"/>
<dScrollBoard></dScrollBoard>
</div>
</template>
<script setup>
import { inject, onMounted, onUnmounted, ref } from 'vue'
import HelloWorld from "@/components/HelloWorld.vue"
import {dInput, dScrollBoard} from 'black-knight/lib/components'
var event = inject("event")
var value = ref('')
onMounted(()=>{
onUnmounted(event.on("home",data=>{console.log(data,'=======event----------home--1111--')}))
})
</script>

10
src/views/home.vue

@ -0,0 +1,10 @@
<style lang="less" scoped>
</style>
<template>
</template>
<script setup>
import { inject, onMounted, onUnmounted, ref } from 'vue'
</script>
Loading…
Cancel
Save