!27 use Vue ref for dom

Merge pull request !27 from pauli/master
This commit is contained in:
lyt-Top 2022-06-04 11:23:46 +00:00 committed by Gitee
commit 7d004ee948
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 63 additions and 52 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="editor-container"> <div class="editor-container">
<div id="editor-toolbar"></div> <div ref="editorToolbar"></div>
<div :id="id" :style="{ height }"></div> <div ref="editorContent" :style="{ height }"></div>
</div> </div>
</template> </template>
@ -13,6 +13,8 @@ import { toolbarKeys } from './toolbar';
// //
interface WangeditorState { interface WangeditorState {
editorToolbar: HTMLDivElement | null;
editorContent: HTMLDivElement | null;
editor: any; editor: any;
} }
@ -51,7 +53,9 @@ export default defineComponent({
}, },
setup(props, { emit }) { setup(props, { emit }) {
const state = reactive<WangeditorState>({ const state = reactive<WangeditorState>({
editorToolbar: null,
editor: null, editor: null,
editorContent: null,
}); });
// //
const wangeditorConfig = () => { const wangeditorConfig = () => {
@ -79,13 +83,13 @@ export default defineComponent({
const initWangeditor = () => { const initWangeditor = () => {
state.editor = createEditor({ state.editor = createEditor({
html: props.modelValue, html: props.modelValue,
selector: `#${props.id}`, selector: state.editorContent!,
config: wangeditorConfig(), config: wangeditorConfig(),
mode: props.mode, mode: props.mode,
}); });
createToolbar({ createToolbar({
editor: state.editor, editor: state.editor,
selector: '#editor-toolbar', selector: state.editorToolbar!,
mode: props.mode, mode: props.mode,
config: toolbarConfig(), config: toolbarConfig(),
}); });

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="layout-view-bg-white flex mt1" :style="{ height: `calc(100vh - ${setIframeHeight}`, border: 'none' }" v-loading="iframeLoading"> <div class="layout-view-bg-white flex mt1" :style="{ height: `calc(100vh - ${setIframeHeight}`, border: 'none' }" v-loading="iframeLoading">
<iframe :src="iframeUrl" frameborder="0" height="100%" width="100%" id="iframe" v-show="!iframeLoading"></iframe> <iframe :src="iframeUrl" frameborder="0" height="100%" width="100%" ref="iframeDom" v-show="!iframeLoading"></iframe>
</div> </div>
</template> </template>
@ -20,6 +20,7 @@ export default defineComponent({
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes); const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
const route = useRoute(); const route = useRoute();
const state = reactive({ const state = reactive({
iframeDom: null as HTMLIFrameElement | null,
iframeLoading: true, iframeLoading: true,
iframeUrl: '', iframeUrl: '',
}); });
@ -28,7 +29,7 @@ export default defineComponent({
state.iframeUrl = <any>route.meta.isLink; state.iframeUrl = <any>route.meta.isLink;
nextTick(() => { nextTick(() => {
state.iframeLoading = true; state.iframeLoading = true;
const iframe = document.getElementById('iframe'); const iframe = state.iframeDom;
if (!iframe) return false; if (!iframe) return false;
iframe.onload = () => { iframe.onload = () => {
state.iframeLoading = false; state.iframeLoading = false;

View File

@ -1,20 +1,18 @@
<template> <template>
<div id="printRref"> <el-card shadow="hover" header="复制剪切演示">
<el-card shadow="hover" header="复制剪切演示"> <el-alert
<el-alert title="感谢优秀的 `vue-clipboard3`项目地址https://github.com/JamieCurnow/vue-clipboard3`"
title="感谢优秀的 `vue-clipboard3`项目地址https://github.com/JamieCurnow/vue-clipboard3`" type="success"
type="success" :closable="false"
:closable="false" class="mb15"
class="mb15" ></el-alert>
></el-alert> <el-input placeholder="请输入内容" v-model="copyVal">
<el-input placeholder="请输入内容" v-model="copyVal"> <template #append>
<template #append> <el-button @click="copyText(copyVal)">复制链接</el-button>
<el-button @click="copyText(copyVal)">复制链接</el-button> </template>
</template> </el-input>
</el-input> <el-input placeholder="先点击上方 `复制链接` 按钮,然后 `Ctrl + V` 进行粘贴! " v-model="shearVal" class="mt15"> </el-input>
<el-input placeholder="先点击上方 `复制链接` 按钮,然后 `Ctrl + V` 进行粘贴! " v-model="shearVal" class="mt15"> </el-input> </el-card>
</el-card>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">

View File

@ -10,11 +10,11 @@
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :sm="6" class="mb15" v-for="(v, k) in topCardItemList" :key="k"> <el-col :sm="6" class="mb15" v-for="(v, k) in topCardItemList" :key="k">
<div class="countup-card-item countup-card-item-box" :style="{ background: `var(${v.color})` }"> <div class="countup-card-item countup-card-item-box" :style="{ background: `var(${v.color})` }">
<div class="countup-card-item-flex"> <div class="countup-card-item-flex" ref="topCardItemRefs">
<div class="countup-card-item-title pb3">{{ v.title }}</div> <div class="countup-card-item-title pb3">{{ v.title }}</div>
<div class="countup-card-item-title-num pb6" :id="`titleNum${k + 1}`"></div> <div class="countup-card-item-title-num pb6"></div>
<div class="countup-card-item-tip pb3">{{ v.tip }}</div> <div class="countup-card-item-tip pb3">{{ v.tip }}</div>
<div class="countup-card-item-tip-num" :id="`tipNum${k + 1}`"></div> <div class="countup-card-item-tip-num"></div>
</div> </div>
<i :class="v.icon" :style="{ color: v.iconColor }"></i> <i :class="v.icon" :style="{ color: v.iconColor }"></i>
</div> </div>
@ -44,6 +44,7 @@ export default defineComponent({
name: 'funCountup', name: 'funCountup',
setup() { setup() {
const state = reactive({ const state = reactive({
topCardItemRefs: null as any,
topCardItemList: [ topCardItemList: [
{ {
title: '今日访问人数', title: '今日访问人数',
@ -86,14 +87,10 @@ export default defineComponent({
// //
const initNumCountUp = () => { const initNumCountUp = () => {
nextTick(() => { nextTick(() => {
new CountUp('titleNum1', Math.random() * 10000).start(); state.topCardItemRefs.forEach((v: HTMLDivElement) => {
new CountUp('titleNum2', Math.random() * 10000).start(); new CountUp(v.querySelector('.countup-card-item-title-num') as HTMLDivElement, Math.random() * 10000).start();
new CountUp('titleNum3', Math.random() * 10000).start(); new CountUp(v.querySelector('.countup-card-item-tip-num') as HTMLDivElement, Math.random() * 1000).start();
new CountUp('titleNum4', Math.random() * 10000).start(); });
new CountUp('tipNum1', Math.random() * 1000).start();
new CountUp('tipNum2', Math.random() * 1000).start();
new CountUp('tipNum3', Math.random() * 1000).start();
new CountUp('tipNum4', Math.random() * 1000).start();
}); });
}; };
// / // /

View File

@ -1,7 +1,7 @@
<template> <template>
<div :style="{ height: `calc(100vh - ${initTagViewHeight}` }"> <div :style="{ height: `calc(100vh - ${initTagViewHeight}` }">
<div class="layout-view-bg-white"> <div class="layout-view-bg-white">
<div id="echartsMap" style="height: 100%"></div> <div ref="echartsMap" style="height: 100%"></div>
</div> </div>
</div> </div>
</template> </template>
@ -23,6 +23,7 @@ export default defineComponent({
const { themeConfig } = storeToRefs(storesThemeConfig); const { themeConfig } = storeToRefs(storesThemeConfig);
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes); const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
const state: any = reactive({ const state: any = reactive({
echartsMap: null,
echartsMapList, echartsMapList,
echartsMapData, echartsMapData,
}); });
@ -52,7 +53,7 @@ export default defineComponent({
}; };
// echartsMap // echartsMap
const initEchartsMap = () => { const initEchartsMap = () => {
const myChart = echarts.init(<HTMLElement>document.getElementById('echartsMap')); const myChart = echarts.init(<HTMLElement>state.echartsMap);
const option = { const option = {
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',

View File

@ -1,5 +1,5 @@
<template> <template>
<div id="printRef"> <div ref="printRef">
<el-card shadow="hover" header="打印演示"> <el-card shadow="hover" header="打印演示">
<el-alert <el-alert
title="感谢优秀的 `print-js`项目地址https://github.com/crabbly/Print.js。请在打印弹窗 `更多设置` 中开启 `背景图形。`" title="感谢优秀的 `print-js`项目地址https://github.com/crabbly/Print.js。请在打印弹窗 `更多设置` 中开启 `背景图形。`"
@ -22,11 +22,13 @@ import printJs from 'print-js';
export default defineComponent({ export default defineComponent({
name: 'funPrintJs', name: 'funPrintJs',
setup() { setup() {
const state = reactive({}); const state = reactive({
printRef: null as null | HTMLDivElement,
});
// //
const onPrintJs = () => { const onPrintJs = () => {
printJs({ printJs({
printable: 'printRef', printable: state.printRef,
type: 'html', type: 'html',
css: ['//at.alicdn.com/t/font_2298093_o73r8wjdhlg.css', '//unpkg.com/element-plus/dist/index.css'], css: ['//at.alicdn.com/t/font_2298093_o73r8wjdhlg.css', '//unpkg.com/element-plus/dist/index.css'],
scanStyles: false, scanStyles: false,

View File

@ -23,7 +23,7 @@
</el-card> </el-card>
<el-dialog v-model="dialogVisible" width="769px"> <el-dialog v-model="dialogVisible" width="769px">
<template #title> <template #header>
<div v-drag="['.drag-container .el-dialog', '.drag-container .el-dialog__header']">拖动指令效果v-drag</div> <div v-drag="['.drag-container .el-dialog', '.drag-container .el-dialog__header']">拖动指令效果v-drag</div>
</template> </template>
<p>鼠标放标题头进行 Dialog 对话框拖动</p> <p>鼠标放标题头进行 Dialog 对话框拖动</p>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="workflow-tool-help"> <div class="workflow-tool-help">
<el-dialog v-model="isShow" width="769px"> <el-dialog v-model="isShow" width="769px">
<template #title> <template #header>
<div v-drag="['.workflow-tool-help .el-dialog', '.workflow-tool-help .el-dialog__header']">使用帮助</div> <div v-drag="['.workflow-tool-help .el-dialog', '.workflow-tool-help .el-dialog__header']">使用帮助</div>
</template> </template>
<div>1拖入鼠标移入左侧导航中鼠标形状改变时拖动到右侧网格状的视图中</div> <div>1拖入鼠标移入左侧导航中鼠标形状改变时拖动到右侧网格状的视图中</div>

View File

@ -8,10 +8,10 @@
<!-- 左侧导航区 --> <!-- 左侧导航区 -->
<div class="workflow-content"> <div class="workflow-content">
<div id="workflow-left"> <div class="workflow-left">
<el-scrollbar> <el-scrollbar>
<div <div
:id="`left${key}`" ref="leftNavRefs"
v-for="(val, key) in leftNavList" v-for="(val, key) in leftNavList"
:key="val.id" :key="val.id"
:style="{ height: val.isOpen ? 'auto' : '50px', overflow: 'hidden' }" :style="{ height: val.isOpen ? 'auto' : '50px', overflow: 'hidden' }"
@ -32,11 +32,12 @@
</div> </div>
<!-- 右侧绘画区 --> <!-- 右侧绘画区 -->
<div id="workflow-right"> <div class="workflow-right" ref="workflowRightRef">
<div <div
v-for="(v, k) in jsplumbData.nodeList" v-for="(v, k) in jsplumbData.nodeList"
:key="v.nodeId" :key="v.nodeId"
:id="v.nodeId" :id="v.nodeId"
:data-node-id="v.nodeId"
:class="v.class" :class="v.class"
:style="{ left: v.left, top: v.top }" :style="{ left: v.left, top: v.top }"
@click="onItemCloneClick(k)" @click="onItemCloneClick(k)"
@ -102,6 +103,8 @@ interface XyState {
y: string | number; y: string | number;
} }
interface WorkflowState { interface WorkflowState {
workflowRightRef: HTMLDivElement | null;
leftNavRefs: any[];
leftNavList: any[]; leftNavList: any[];
dropdownNode: XyState; dropdownNode: XyState;
dropdownLine: XyState; dropdownLine: XyState;
@ -132,6 +135,8 @@ export default defineComponent({
const { isTagsViewCurrenFull } = storeToRefs(stores); const { isTagsViewCurrenFull } = storeToRefs(stores);
const { copyText } = commonFunction(); const { copyText } = commonFunction();
const state = reactive<WorkflowState>({ const state = reactive<WorkflowState>({
workflowRightRef: null as HTMLDivElement | null,
leftNavRefs: [],
leftNavList: [], leftNavList: [],
dropdownNode: { x: '', y: '' }, dropdownNode: { x: '', y: '' },
dropdownLine: { x: '', y: '' }, dropdownLine: { x: '', y: '' },
@ -195,8 +200,8 @@ export default defineComponent({
}; };
// - // -
const initSortable = () => { const initSortable = () => {
state.leftNavList.forEach((v, k) => { state.leftNavRefs.forEach(v => {
Sortable.create(document.getElementById(`left${k}`) as HTMLElement, { Sortable.create(v as HTMLDivElement, {
group: { group: {
name: 'vue-next-admin-1', name: 'vue-next-admin-1',
pull: 'clone', pull: 'clone',
@ -209,7 +214,7 @@ export default defineComponent({
onEnd: function (evt: any) { onEnd: function (evt: any) {
const { name, icon, id } = evt.clone.dataset; const { name, icon, id } = evt.clone.dataset;
const { layerX, layerY, clientX, clientY } = evt.originalEvent; const { layerX, layerY, clientX, clientY } = evt.originalEvent;
const el = document.querySelector('#workflow-right') as HTMLElement; const el = state.workflowRightRef!;
const { x, y, width, height } = el.getBoundingClientRect(); const { x, y, width, height } = el.getBoundingClientRect();
if (clientX < x || clientX > width + x || clientY < y || y > y + height) { if (clientX < x || clientX > width + x || clientY < y || y > y + height) {
ElMessage.warning('请把节点拖入到画布中'); ElMessage.warning('请把节点拖入到画布中');
@ -546,7 +551,7 @@ export default defineComponent({
.workflow-content { .workflow-content {
display: flex; display: flex;
height: calc(100% - 35px); height: calc(100% - 35px);
#workflow-left { .workflow-left {
width: 220px; width: 220px;
height: 100%; height: 100%;
border-right: 1px solid var(--el-border-color-light, #ebeef5); border-right: 1px solid var(--el-border-color-light, #ebeef5);
@ -607,7 +612,7 @@ export default defineComponent({
} }
} }
} }
#workflow-right { .workflow-right {
flex: 1; flex: 1;
position: relative; position: relative;
overflow: hidden; overflow: hidden;

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="visualizing-demo1"> <div class="visualizing-demo1">
<!-- 地图 --> <!-- 地图 -->
<div id="visualizingDemo1" style="height: 100%"></div> <div ref="visualizingDemo1" style="height: 100%"></div>
<div class="visualizing-container"> <div class="visualizing-container">
<!-- 头部 --> <!-- 头部 -->
<div class="visualizing-container-head"> <div class="visualizing-container-head">
@ -98,6 +98,7 @@ import { echartsMapList, echartsMapData, echartsMapImgs } from './mock/demo1';
// //
interface Demo1State { interface Demo1State {
visualizingDemo1: any;
echartsMapList: any; echartsMapList: any;
echartsMapData: any; echartsMapData: any;
echartsMapImgs: any; echartsMapImgs: any;
@ -110,6 +111,7 @@ export default defineComponent({
setup() { setup() {
const { proxy } = <any>getCurrentInstance(); const { proxy } = <any>getCurrentInstance();
const state = reactive<Demo1State>({ const state = reactive<Demo1State>({
visualizingDemo1: null,
echartsMapList, echartsMapList,
echartsMapData, echartsMapData,
echartsMapImgs, echartsMapImgs,
@ -142,7 +144,7 @@ export default defineComponent({
}; };
// echartsMap // echartsMap
const initEchartsMap = () => { const initEchartsMap = () => {
const myChart = echarts.init(<HTMLElement>document.getElementById('visualizingDemo1')); const myChart = echarts.init(<HTMLElement>state.visualizingDemo1);
const option = { const option = {
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',

View File

@ -127,7 +127,7 @@
<div class="big-data-down-center"> <div class="big-data-down-center">
<div class="big-data-down-center-one"> <div class="big-data-down-center-one">
<div class="big-data-down-center-one-content" ref="rightChartData5"> <div class="big-data-down-center-one-content" ref="rightChartData5">
<div id="3DEarth"></div> <div ref="the3DEarth"></div>
<div :class="v.topLevelClass" v-for="(v, k) in earth3DBtnList" :key="k"> <div :class="v.topLevelClass" v-for="(v, k) in earth3DBtnList" :key="k">
<div class="circle" v-for="i in 4" :key="i"></div> <div class="circle" v-for="i in 4" :key="i"></div>
<div class="text-box"> <div class="text-box">
@ -256,6 +256,7 @@ export default defineComponent({
earth3DBtnList, earth3DBtnList,
chartData4List, chartData4List,
myCharts: [], myCharts: [],
the3DEarth: null as HTMLDivElement | null,
}); });
// //
const initTime = () => { const initTime = () => {
@ -685,7 +686,7 @@ export default defineComponent({
}; };
// 3DEarth // 3DEarth
const init3DEarth = (globeRadius) => { const init3DEarth = (globeRadius) => {
let el = document.getElementById('3DEarth'); let el = state.the3DEarth!;
el.style.height = `${proxy.$refs.rightChartData5.offsetHeight}px`; el.style.height = `${proxy.$refs.rightChartData5.offsetHeight}px`;
const myChart = echarts.init(el); const myChart = echarts.init(el);
const option = { const option = {