2023-10-07 14:29:43 +08:00
|
|
|
|
<!--
|
|
|
|
|
filename: design.vue
|
|
|
|
|
author: liubin
|
|
|
|
|
date: 2023-10-07 13:14:40
|
|
|
|
|
description: 设计打印模板
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="print-design">
|
|
|
|
|
<section id="menu">
|
|
|
|
|
<NavMenu @action="handleAction" :menu="menu" />
|
|
|
|
|
</section>
|
|
|
|
|
<section id="main-panel">
|
2023-10-08 10:18:08 +08:00
|
|
|
|
<section id="left-panel">
|
|
|
|
|
<h2>组件</h2>
|
|
|
|
|
<div id="components"></div>
|
|
|
|
|
</section>
|
2023-10-07 14:29:43 +08:00
|
|
|
|
<section id="edit-panel"></section>
|
2023-10-08 10:18:08 +08:00
|
|
|
|
<section id="right-panel">
|
|
|
|
|
<h2>设置</h2>
|
|
|
|
|
<div id="settings"></div>
|
|
|
|
|
</section>
|
2023-10-07 14:29:43 +08:00
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2023-10-08 10:18:08 +08:00
|
|
|
|
|
|
|
|
|
import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint";
|
|
|
|
|
hiprint.init({
|
|
|
|
|
providers: [defaultElementTypeProvider()],
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-07 14:29:43 +08:00
|
|
|
|
const NavSelector = {
|
|
|
|
|
name: 'NavSelector',
|
|
|
|
|
props: ['name', 'options'],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
open: false,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleOpen() {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
// this.$emit('closeOtherMenu', this)
|
|
|
|
|
// this.$emit('hover', this)
|
2023-10-07 14:29:43 +08:00
|
|
|
|
this.open = !this.open;
|
|
|
|
|
},
|
2023-10-08 10:18:08 +08:00
|
|
|
|
handleClickItem(e) {
|
|
|
|
|
this.$emit('click', e.target.innerText)
|
|
|
|
|
},
|
2023-10-07 14:29:43 +08:00
|
|
|
|
// 暴露一个close方法,供父组件调用
|
|
|
|
|
closeSubMenu() {
|
|
|
|
|
this.open = false;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
render: function (h) {
|
|
|
|
|
return (
|
2023-10-08 10:18:08 +08:00
|
|
|
|
<li class={'nav-selector__item'} onMouseenter={this.handleOpen} onMouseleave={this.handleOpen}>
|
2023-10-07 14:29:43 +08:00
|
|
|
|
<span class={'nav-selector__name'}>{this.name}</span>
|
|
|
|
|
<ul class={`${this.open ? '' : 'hidden'} nav-selector__submenu-items`}>
|
|
|
|
|
{this.options.map((item) => {
|
|
|
|
|
return <li onClick={this.handleClickItem}>{item}</li>;
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const NavMenu = {
|
|
|
|
|
name: 'NavMenu',
|
|
|
|
|
props: ['menu'],
|
|
|
|
|
components: { NavSelector },
|
|
|
|
|
data() {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
return {}
|
|
|
|
|
},
|
2023-10-07 14:29:43 +08:00
|
|
|
|
methods: {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
handleCloseOtherMenu(vueInstance) {
|
|
|
|
|
this.$children.forEach(vm => {
|
|
|
|
|
if (vm != vueInstance) {
|
|
|
|
|
vm.closeSubMenu()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleItemClicked(e) {
|
|
|
|
|
this.$emit('action', e);
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-10-07 14:29:43 +08:00
|
|
|
|
render: function (h) {
|
|
|
|
|
return (
|
|
|
|
|
<ul class={'nav-menu'}>
|
|
|
|
|
{this.menu.map((item) => {
|
|
|
|
|
return <NavSelector onClick={this.handleItemClicked} onCloseOtherMenu={this.handleCloseOtherMenu} name={item.name} options={item.options} />;
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
name: 'PrintDesignPage',
|
2023-10-07 14:29:43 +08:00
|
|
|
|
components: { NavMenu },
|
|
|
|
|
props: {},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
hiprintTemplate: null,
|
2023-10-07 14:29:43 +08:00
|
|
|
|
menu: [
|
|
|
|
|
{
|
|
|
|
|
name: '菜单',
|
|
|
|
|
options: ['新建', '打开', '保存', '另存为', '导出', '打印', '退出'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '视图',
|
|
|
|
|
options: ['编辑', '布局'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {},
|
2023-10-08 10:18:08 +08:00
|
|
|
|
mounted() {
|
|
|
|
|
this.loadSideBar();
|
|
|
|
|
this.loadDesigner();
|
|
|
|
|
},
|
2023-10-07 14:29:43 +08:00
|
|
|
|
methods: {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
loadDesigner() {
|
|
|
|
|
$("#edit-panel").empty();
|
|
|
|
|
this.hiprintTemplate = new hiprint.PrintTemplate({
|
|
|
|
|
settingContainer: "#settings",
|
|
|
|
|
});
|
|
|
|
|
this.hiprintTemplate.design("#edit-panel");
|
|
|
|
|
},
|
|
|
|
|
loadSideBar() {
|
|
|
|
|
this.loadProviders();
|
|
|
|
|
this.loadSettings();
|
|
|
|
|
},
|
|
|
|
|
loadProviders() { },
|
|
|
|
|
loadSettings() { },
|
|
|
|
|
handleAction(name) {
|
|
|
|
|
console.log('name', name)
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-10-07 14:29:43 +08:00
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.print-design {
|
|
|
|
|
height: 100vh;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#main-panel {
|
|
|
|
|
height: 1px;
|
|
|
|
|
flex: 1;
|
|
|
|
|
display: grid;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
grid-template-columns: 1fr 3fr 1fr;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
grid-auto-rows: 1fr;
|
|
|
|
|
grid-template-areas: 'left main right';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#menu {
|
|
|
|
|
// background: black;
|
|
|
|
|
// color: white;
|
|
|
|
|
background: #fff;
|
|
|
|
|
border-bottom: 1px solid #ccc;
|
|
|
|
|
|
2023-10-08 10:18:08 +08:00
|
|
|
|
>ul {
|
2023-10-07 14:29:43 +08:00
|
|
|
|
// background: #32aa32;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
padding: 0;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
list-style: none;
|
|
|
|
|
margin: 0;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
margin-left: 10px;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#left-panel {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
overflow: auto;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
grid-area: left;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
background: #fff;
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
padding: 4px 20px;
|
|
|
|
|
border-bottom: 1px solid #ccc;
|
|
|
|
|
background: #ccc;
|
|
|
|
|
}
|
2023-10-07 14:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#edit-panel {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
padding: 20px;
|
|
|
|
|
overflow: auto;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
grid-area: main;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
justify-items: center;
|
|
|
|
|
background: #fff;
|
|
|
|
|
border-left: 1px solid #ccc;
|
|
|
|
|
border-right: 1px solid #ccc;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#right-panel {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
overflow: auto;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
grid-area: right;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
background: #fff;
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
padding: 4px 12px;
|
|
|
|
|
border-bottom: 1px solid #ccc;
|
|
|
|
|
background: #ccc;
|
|
|
|
|
}
|
2023-10-07 14:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
// 子组件的样式
|
|
|
|
|
.nav-selector__item {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
font-size: 18px;
|
|
|
|
|
letter-spacing: 1px;
|
|
|
|
|
// font-weight: 600;
|
|
|
|
|
padding: 6px 12px;
|
|
|
|
|
line-height: 1.25;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
2023-10-08 10:18:08 +08:00
|
|
|
|
&:hover {
|
|
|
|
|
background: #f1f1f1;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ul {
|
|
|
|
|
list-style: none;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
position: absolute;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
top: 100%;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
min-width: 128px;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
left: 0px;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
background: #fff;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
// border-radius: 4px;
|
|
|
|
|
margin: 0;
|
|
|
|
|
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
|
|
|
|
|
z-index: 100;
|
|
|
|
|
|
|
|
|
|
li {
|
2023-10-08 10:18:08 +08:00
|
|
|
|
padding: 6px 12px;
|
2023-10-07 14:29:43 +08:00
|
|
|
|
cursor: pointer;
|
2023-10-08 10:18:08 +08:00
|
|
|
|
|
2023-10-07 14:29:43 +08:00
|
|
|
|
&:hover {
|
|
|
|
|
background: #f1f1f1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.hidden {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|