Commit 786add6f41b5f24291b2d8303c17a26ddd095b92

Authored by ww
1 parent 08602c0d

feat: add upload layer component

7.17 KB | W: | H:

36.2 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
@@ -9,7 +9,8 @@ @@ -9,7 +9,8 @@
9 this.createVertexTemplateEntry('text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;', 100, 40, '变量', '变量', null, null, '变量'), 9 this.createVertexTemplateEntry('text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;', 100, 40, '变量', '变量', null, null, '变量'),
10 this.createEdgeTemplateEntry('shape=filledEdge;rounded=1;fixDash=1;endArrow=none;strokeWidth=10;fillColor=#BAFDFF;edgeStyle=orthogonalEdgeStyle;flowAnimation=1;strokeColor=#6666FF;endFill=1;metaEdit=0;backgroundOutline=0;', 60, 40, '', '线条'), 10 this.createEdgeTemplateEntry('shape=filledEdge;rounded=1;fixDash=1;endArrow=none;strokeWidth=10;fillColor=#BAFDFF;edgeStyle=orthogonalEdgeStyle;flowAnimation=1;strokeColor=#6666FF;endFill=1;metaEdit=0;backgroundOutline=0;', 60, 40, '', '线条'),
11 this.addEntry('real time', mxUtils.bind(this, function () { 11 this.addEntry('real time', mxUtils.bind(this, function () {
12 - const template = `<div class="thingKit-component__real-time"><div class="real-time__date">%currentDate%</div> <div style="font-size:30px" class="real-time__now">%date{HH:MM:ss}%</div></div>` 12 + // const template = `<div class="thingKit-component__real-time"><div class="real-time__date">%currentDate%</div> <div style="font-size:30px" class="real-time__now">%date{HH:MM:ss}%</div></div>`
  13 + const template = `<div class="thingKit-component__real-time"><div class="real-time__date"></div> <div style="font-size:30px" class="real-time__now">时间</div></div>`
13 const cell = new mxCell(template, new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); 14 const cell = new mxCell(template, new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
14 cell.vertex = true; 15 cell.vertex = true;
15 this.graph.setAttributeForCell(cell, 'placeholders', '1'); 16 this.graph.setAttributeForCell(cell, 'placeholders', '1');
@@ -22,14 +23,6 @@ @@ -22,14 +23,6 @@
22 this.setCellAttributes(cell, { componentType: 'variableImage' }) 23 this.setCellAttributes(cell, { componentType: 'variableImage' })
23 return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '变量图片'); 24 return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '变量图片');
24 })) 25 }))
25 - // this.addEntry('variableImage', mxUtils.bind(this, function () {  
26 - // const imagePlaceholder = '/thingskit-drawio/images/thingskit/img-placeholder.png';  
27 - // const template = `<div><img src="${imagePlaceholder}" alt=""></div>`;  
28 - // const cell = new mxCell(template, new mxGeometry(0, 0, 194, 195), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');  
29 - // cell.vertex = true;  
30 - // this.graph.setAttributeForCell(cell, 'componentType', 'variableImage');  
31 - // return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '变量图片');  
32 - // }))  
33 ]; 26 ];
34 27
35 this.addPaletteFunctions('component', '基础元件', true, fns); 28 this.addPaletteFunctions('component', '基础元件', true, fns);
@@ -46,4 +39,19 @@ @@ -46,4 +39,19 @@
46 var day = date.getDay(); 39 var day = date.getDay();
47 return year + '年' + month + '月' + dates + '日 ' + arr[day]; 40 return year + '年' + month + '月' + dates + '日 ' + arr[day];
48 } 41 }
  42 +
  43 + /**
  44 + * @description 初始化实时事件组件
  45 + */
  46 + function initRealTimeComponent() {
  47 + RAFSetInterval(() => {
  48 + const allTimeNode = document.querySelectorAll('.thingKit-component__real-time .real-time__now')
  49 + for (const time of allTimeNode) {
  50 + const date = new Date()
  51 + time.innerHTML = `${date.getHours() < 10 ? '0' : ''}${date.getHours()}:${date.getMinutes() < 10 ? '0' : ''}${date.getMinutes()}:${date.getSeconds() < 10 ? '0' : ''}${date.getSeconds()}`
  52 + }
  53 + }, 1000)
  54 + }
  55 +
  56 + initRealTimeComponent()
49 })(); 57 })();
@@ -4881,8 +4881,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -4881,8 +4881,9 @@ DataFormatPanel.prototype.addDataFont = function (container) {
4881 const sidebarInstance = ui.sidebar 4881 const sidebarInstance = ui.sidebar
4882 // console.log(this.editorUi) 4882 // console.log(this.editorUi)
4883 console.log(vertices) 4883 console.log(vertices)
4884 - console.log(this) 4884 + console.log(ui)
4885 4885
  4886 + const hasModifyNotSave = editor.status
4886 4887
4887 // console.log(vertices[0]?.get('bindType')) 4888 // console.log(vertices[0]?.get('bindType'))
4888 /** 4889 /**
@@ -4941,6 +4942,18 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -4941,6 +4942,18 @@ DataFormatPanel.prototype.addDataFont = function (container) {
4941 let currentNodeData = null 4942 let currentNodeData = null
4942 4943
4943 /** 4944 /**
  4945 + * @description 保存页面信息
  4946 + */
  4947 + async function autoSaveGraphInfo() {
  4948 + if (!hasModifyNotSave) return
  4949 + ui.actions.get(
  4950 + (ui.currentFile.mode == null || !ui.currentFile.isEditable())
  4951 + ? 'saveAs'
  4952 + : 'save')
  4953 + .funct();
  4954 + }
  4955 +
  4956 + /**
4944 * @description 获取弹出层绑定信息 4957 * @description 获取弹出层绑定信息
4945 * @param {'DOWN' | 'UP' | 'SINGLE' | 'DOUBLE' | 'DISPLAY' | 'FLASH' | 'ROTATE' | 'IMAGE'} type - 类型 4958 * @param {'DOWN' | 'UP' | 'SINGLE' | 'DOUBLE' | 'DISPLAY' | 'FLASH' | 'ROTATE' | 'IMAGE'} type - 类型
4946 * @param {'event' | 'act' } category - 类别 4959 * @param {'event' | 'act' } category - 类别
@@ -5036,19 +5049,22 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5036,19 +5049,22 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5036 GATEWAY: 'GATEWAY', 5049 GATEWAY: 'GATEWAY',
5037 } 5050 }
5038 5051
  5052 + /**
  5053 + * @description 刷新页面
  5054 + */
5039 function echoRefreshFn() { 5055 function echoRefreshFn() {
5040 } 5056 }
5041 5057
5042 5058
5043 // 获取url的请求参数函数 5059 // 获取url的请求参数函数
5044 function getRequest() { 5060 function getRequest() {
5045 - var url = location.search; //获取url中"?"符后的字串  
5046 - var theRequest = new Object(); 5061 + let url = location.search; //获取url中"?"符后的字串
  5062 + let theRequest = new Object();
5047 if (url.indexOf("?") != -1) { 5063 if (url.indexOf("?") != -1) {
5048 var str = url.substring(1); 5064 var str = url.substring(1);
5049 - strs = str.split("&");  
5050 - for (var i = 0; i < strs.length; i++) {  
5051 - theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); 5065 + string = str.split("&");
  5066 + for (var i = 0; i < string.length; i++) {
  5067 + theRequest[string[i].split("=")[0]] = decodeURI(string[i].split("=")[1]);
5052 } 5068 }
5053 } 5069 }
5054 return theRequest; 5070 return theRequest;
@@ -5338,6 +5354,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5338,6 +5354,9 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5338 // 5354 //
5339 // } 5355 // }
5340 5356
  5357 + /**
  5358 + * @description 创建数据面板
  5359 + */
5341 function createDataSourcePanel() { 5360 function createDataSourcePanel() {
5342 const fragment = document.createDocumentFragment() 5361 const fragment = document.createDocumentFragment()
5343 const defaultPanel = createPanel() 5362 const defaultPanel = createPanel()
@@ -5482,6 +5501,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5482,6 +5501,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5482 }) 5501 })
5483 } 5502 }
5484 } 5503 }
  5504 + await to(autoSaveGraphInfo())
5485 const [err, res] = await to(ConfigurationNodeApi.updateNodeInfo(value)) 5505 const [err, res] = await to(ConfigurationNodeApi.updateNodeInfo(value))
5486 if (err) return 5506 if (err) return
5487 UseLayUi.successMsg() 5507 UseLayUi.successMsg()
@@ -5491,7 +5511,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5491,7 +5511,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5491 } 5511 }
5492 5512
5493 /** 5513 /**
5494 - * @description 5514 + * @description 处理设置变量图片
5495 */ 5515 */
5496 function handleSettingVarImage(event) { 5516 function handleSettingVarImage(event) {
5497 5517
@@ -5557,66 +5577,6 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5557,66 +5577,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5557 DEL_ROW_EL: 'variableImageTableDelRow', 5577 DEL_ROW_EL: 'variableImageTableDelRow',
5558 5578
5559 /** 5579 /**
5560 - * @description 图片选中区域节点  
5561 - */  
5562 - IMG_SELECT_CONTAINER_EL: 'imgSelectContainerEl',  
5563 -  
5564 - /**  
5565 - * @description 切换图片来源控制  
5566 - */  
5567 - SWITCH_IMG_ORIGIN_FILTER: 'switchImgOriginFilter',  
5568 -  
5569 - /**  
5570 - * @description 图片选中侧边栏节点  
5571 - */  
5572 - VAR_IMG_CONTAINER_SIDEBAR: 'var-image__container-sidebar',  
5573 -  
5574 - /**  
5575 - * @description 图库图形选择区域  
5576 - */  
5577 - VAR_IMG_CONTAINER_CONTENT: 'var-image__container-content',  
5578 -  
5579 - /**  
5580 - * @description 图库图形项  
5581 - */  
5582 - VAR_IMG_ITEM: 'var-image__img-item',  
5583 -  
5584 - /**  
5585 - * @description 图库图形选中控制  
5586 - */  
5587 - VAR_IMG_ITEM_CHECKED: 'var-image__img-item--checked',  
5588 -  
5589 - /**  
5590 - * @description 图库图形类别节点  
5591 - */  
5592 - VAR_IMG_CATEGORY: 'var-image__category',  
5593 -  
5594 - /**  
5595 - * @description 图库图形类别选择状态  
5596 - */  
5597 - VAR_IMG_CATEGORY_CHECKED: 'var-image__category--checked',  
5598 -  
5599 - /**  
5600 - * @description 本地上传图片节点  
5601 - */  
5602 - UPLOAD_LOCAL_FILE_EL: 'var-image__container--local',  
5603 -  
5604 - /**  
5605 - * @description 本地上传图片状态  
5606 - */  
5607 - IMAGE_UPLOAD_STATE_EL: 'var-image__upload-state',  
5608 -  
5609 - /**  
5610 - * @description 预览图片状态  
5611 - */  
5612 - IMAGE_PREVIEW_EL: 'preview__img--preview',  
5613 -  
5614 - /**  
5615 - * @description 本地图片上传删除按钮  
5616 - */  
5617 - IMAGE_DEL_PREVIEW_EL: 'var-image__del-icon',  
5618 -  
5619 - /**  
5620 * @description 5580 * @description
5621 */ 5581 */
5622 DATA_SOURCE_COMP_EL: 'varImgDataSourceEl', 5582 DATA_SOURCE_COMP_EL: 'varImgDataSourceEl',
@@ -5660,16 +5620,6 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5660,16 +5620,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5660 IMAGE_GALLERY_IMAGE_PATH: 'imagePath', 5620 IMAGE_GALLERY_IMAGE_PATH: 'imagePath',
5661 } 5621 }
5662 5622
5663 - const enumImageOriginType = {  
5664 - LOCAL: 'local',  
5665 - GALLERY: 'gallery',  
5666 - }  
5667 -  
5668 - /**  
5669 - * @description 图片状态保存  
5670 - */  
5671 - let imageState = {}  
5672 -  
5673 let addRowNumber = 0 5623 let addRowNumber = 0
5674 5624
5675 let getDataSourceValue = () => { 5625 let getDataSourceValue = () => {
@@ -5731,212 +5681,19 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -5731,212 +5681,19 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5731 $(`#${enumActionEl.TABLE_BODY_EL}`).on('click', `.${enumActionEl.SET_IMG_EL}`, (event) => { 5681 $(`#${enumActionEl.TABLE_BODY_EL}`).on('click', `.${enumActionEl.SET_IMG_EL}`, (event) => {
5732 if ($(event.target).hasClass(enumActionEl.DEL_PREVIEW_IMG)) return 5682 if ($(event.target).hasClass(enumActionEl.DEL_PREVIEW_IMG)) return
5733 const rowFilter = $(event.target).parents('tr').attr('lay-filter') 5683 const rowFilter = $(event.target).parents('tr').attr('lay-filter')
5734 - createUploadImgLayer(rowFilter)  
5735 - })  
5736 - } 5684 + // createUploadImgLayer(rowFilter)
  5685 + generatorUploadLayerComponent((imageState) => {
5737 5686
5738 - /**  
5739 - * @description 创建本地图片上传区域  
5740 - */  
5741 - function createLocalFileContainer() {  
5742 - return `  
5743 - <div id="${enumActionEl.UPLOAD_LOCAL_FILE_EL}" class="layui-upload">  
5744 - <div class="preview__img">  
5745 - <img src="" class="layui-upload-img" id="${enumActionEl.IMAGE_PREVIEW_EL}">  
5746 - <div class="var_image__add-icon">+</div>  
5747 - <div class="var-image__del-icon">x</div>  
5748 - </div>  
5749 - <div class="layui-upload-list"></div>  
5750 - </div>  
5751 - <div id="${enumActionEl.IMAGE_UPLOAD_STATE_EL}"></div>  
5752 - <div style="margin-top: 30px;">图片格式支持pngjpg(jpeg)gif,大小不能超过5M</div>  
5753 - `  
5754 - }  
5755 -  
5756 - /**  
5757 - * @description 上传  
5758 - */  
5759 - function uploadFileEvent() {  
5760 - $(`.${enumActionEl.IMAGE_DEL_PREVIEW_EL}`).on('click', (event) => {  
5761 - event.stopPropagation()  
5762 - $(`#${enumActionEl.IMAGE_PREVIEW_EL}`).attr('src', '')  
5763 - imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = null  
5764 - })  
5765 - const uploadInst = upload.render({  
5766 - elem: `#${enumActionEl.UPLOAD_LOCAL_FILE_EL}`,  
5767 - auto: false,  
5768 - size: 1024 * 5,  
5769 - url: '/yt/oss/upload',  
5770 - method: 'post',  
5771 - choose(obj) {  
5772 - obj.preview(async function (index, file, result) {  
5773 - const formData = new FormData()  
5774 - formData.set('file', file)  
5775 - const [err, res] = await to(ConfigurationNodeApi.uploadImg(formData))  
5776 - if (!err) {  
5777 - $(`#${enumActionEl.IMAGE_PREVIEW_EL}`).attr('src', result)  
5778 - const { fileStaticUri = '' } = res  
5779 - imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = fileStaticUri  
5780 - }  
5781 - });  
5782 - },  
5783 - });  
5784 - } 5687 + $(`#${enumActionEl.TABLE_BODY_EL}`)
  5688 + .find(`tr[lay-filter="${rowFilter}"]`)
  5689 + .find('img').attr('src', imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH])
5785 5690
5786 - /**  
5787 - * @description 设置选中样式  
5788 - * @param event  
5789 - * @param nodeClass  
5790 - * @param styleClass  
5791 - */  
5792 - function setImageSelectedStyle(event, nodeClass, styleClass) {  
5793 - if (!$(event.target).hasClass(nodeClass)) return  
5794 - $(`.${nodeClass}`).each(function () {  
5795 - $(this).removeClass(styleClass)  
5796 - })  
5797 - $(event.target).addClass(styleClass)  
5798 - }  
5799 -  
5800 - /**  
5801 - * @description 切换图库图形  
5802 - * @param event  
5803 - */  
5804 - function switchGalleryLib(event) {  
5805 - const key = $(event.target).attr(enumConst.IMAGE_GALLERY_CATEGORY)  
5806 - const category = sidebarInstance.getVariableImageLib(key)  
5807 - if (key && category) {  
5808 - $(`#${enumActionEl.VAR_IMG_CONTAINER_CONTENT}`).html(  
5809 - category.lib.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_ITEM}" title="${next.name}"><img src="${next.staticPath}" alt=""></div>`, ''),  
5810 - )  
5811 - }  
5812 - }  
5813 -  
5814 - /**  
5815 - * @description 图片来源事件监听  
5816 - */  
5817 - function generatorSelectImgEventListener() {  
5818 - $(`#${enumActionEl.VAR_IMG_CONTAINER_CONTENT}`).on('click', event => {  
5819 - setImageSelectedStyle(event, enumActionEl.VAR_IMG_ITEM, enumActionEl.VAR_IMG_ITEM_CHECKED)  
5820 - imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = $(event.target).find('img').attr('src')  
5821 - })  
5822 - $(`#${enumActionEl.VAR_IMG_CONTAINER_SIDEBAR}`).on('click', event => {  
5823 - setImageSelectedStyle(event, enumActionEl.VAR_IMG_CATEGORY, enumActionEl.VAR_IMG_CATEGORY_CHECKED)  
5824 - imageState[enumConst.IMAGE_GALLERY_CATEGORY] = $(event.target).attr(enumConst.IMAGE_GALLERY_CATEGORY)  
5825 - imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = null  
5826 - switchGalleryLib(event)  
5827 - })  
5828 - }  
5829 -  
5830 - /**  
5831 - * @description 创建图库图形上传区域  
5832 - */  
5833 - function createGalleryFileContainer() {  
5834 - const category = sidebarInstance.getAllVariableImageLib()  
5835 - const defaultShow = category[0] || { lib: [] }  
5836 - return `  
5837 - <div class="var-image__container--gallery">  
5838 - <div id="${enumActionEl.VAR_IMG_CONTAINER_SIDEBAR}">  
5839 - ${category.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_CATEGORY}" ${enumConst.IMAGE_GALLERY_CATEGORY}="${next.key}">${next.label}</div>`, '')}  
5840 - </div>  
5841 - <div id="${enumActionEl.VAR_IMG_CONTAINER_CONTENT}">  
5842 - ${defaultShow.lib.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_ITEM}" title="${next.name}"><img src="${next.staticPath}" alt=""></div>`, '')}  
5843 - </div>  
5844 - </div>  
5845 - `  
5846 - }  
5847 -  
5848 - /**  
5849 - * @description 切换  
5850 - */  
5851 - function switchUploadImgTypeEventListener() {  
5852 - form.on(`radio(${enumActionEl.SWITCH_IMG_ORIGIN_FILTER})`, event => {  
5853 - const { value } = event  
5854 - imageState = {}  
5855 - if (value === enumImageOriginType.LOCAL) {  
5856 - $(`#${enumActionEl.IMG_SELECT_CONTAINER_EL}`).html(createLocalFileContainer())  
5857 - imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.LOCAL  
5858 - uploadFileEvent()  
5859 - } else if (value === enumImageOriginType.GALLERY) {  
5860 - $(`#${enumActionEl.IMG_SELECT_CONTAINER_EL}`).html(createGalleryFileContainer())  
5861 - const defaultChecked = $(`.${enumActionEl.VAR_IMG_CATEGORY}`).eq(0)  
5862 - defaultChecked.addClass(enumActionEl.VAR_IMG_CATEGORY_CHECKED)  
5863 - imageState[enumConst.IMAGE_GALLERY_CATEGORY] = defaultChecked.attr(enumConst.IMAGE_GALLERY_CATEGORY)  
5864 - imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.GALLERY  
5865 - generatorSelectImgEventListener()  
5866 - }  
5867 - })  
5868 - }  
5869 -  
5870 - /**  
5871 - * @description 设置选中图片及绑定参数  
5872 - * @param rowFilter  
5873 - */  
5874 - function setCheckedImg(rowFilter) {  
5875 - $(`#${enumActionEl.TABLE_BODY_EL}`)  
5876 - .find(`tr[lay-filter="${rowFilter}"]`)  
5877 - .find('img').attr('src', imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH])  
5878 -  
5879 - form.val(rowFilter, {  
5880 - [enumConst.IMAGE_ORIGIN]: imageState[enumConst.IMAGE_ORIGIN],  
5881 - [enumConst.IMAGE_GALLERY_CATEGORY]: imageState[enumConst.IMAGE_GALLERY_CATEGORY],  
5882 - [enumConst.IMAGE_GALLERY_IMAGE_PATH]: imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH],  
5883 - })  
5884 -  
5885 - }  
5886 -  
5887 - /**  
5888 - * @description 初始化并设置默认值  
5889 - */  
5890 - function initSelectImg() {  
5891 - switchUploadImgTypeEventListener()  
5892 - uploadFileEvent()  
5893 - imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.LOCAL  
5894 - form.render()  
5895 - }  
5896 -  
5897 - /**  
5898 - * @description 创建上传图片layer  
5899 - */  
5900 - function createUploadImgLayer(rowFilter) {  
5901 - const content = `  
5902 - <div class="layui-form">  
5903 - <div class="layui-form-item">  
5904 - <div class="var-image__radio">  
5905 - <input type="radio" lay-filter="${enumActionEl.SWITCH_IMG_ORIGIN_FILTER}" name="${enumConst.IMAGE}" value="${enumImageOriginType.LOCAL}" title="本地图片" checked="">  
5906 - <input type="radio" lay-filter="${enumActionEl.SWITCH_IMG_ORIGIN_FILTER}" name="${enumConst.IMAGE}" value="${enumImageOriginType.GALLERY}" title="图库图形">  
5907 - </div>  
5908 - </div>  
5909 - </div>  
5910 - <div id="${enumActionEl.IMG_SELECT_CONTAINER_EL}">  
5911 - ${createLocalFileContainer()}  
5912 - </div>  
5913 - `  
5914 -  
5915 - layer.open({  
5916 - title: '图片',  
5917 - type: 1,  
5918 - content,  
5919 - skin: 'event-layer__override',  
5920 - area: '600px',  
5921 - btn: ["应用", "取消"],  
5922 - shade: ["0.7", "#fafafa"],  
5923 - yes(index) {  
5924 - layer.close(index)  
5925 - setCheckedImg(rowFilter)  
5926 - },  
5927 - but2(index, layero) {  
5928 - imageState = {}  
5929 - layer.close(index)  
5930 - },  
5931 - zIndex: layer.zIndex,  
5932 - async success(layero, index) {  
5933 - layer.setTop(layero);  
5934 - $(layero).addClass('layui-form').find('.layui-layer-btn0').attr({  
5935 - 'lay-submit': '',  
5936 - 'lay-filter': enumActionEl.IMAGE_LAYER_FILTER, 5691 + form.val(rowFilter, {
  5692 + [enumConst.IMAGE_ORIGIN]: imageState[enumConst.IMAGE_ORIGIN],
  5693 + [enumConst.IMAGE_GALLERY_CATEGORY]: imageState[enumConst.IMAGE_GALLERY_CATEGORY],
  5694 + [enumConst.IMAGE_GALLERY_IMAGE_PATH]: imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH],
5937 }) 5695 })
5938 - initSelectImg()  
5939 - }, 5696 + })
5940 }) 5697 })
5941 } 5698 }
5942 5699
@@ -6068,6 +5825,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -6068,6 +5825,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6068 condition: data, 5825 condition: data,
6069 type: event.data.type, 5826 type: event.data.type,
6070 } 5827 }
  5828 + await to(autoSaveGraphInfo())
6071 const [err, res] = await to(ConfigurationNodeApi.updateNodeAct(formModel)) 5829 const [err, res] = await to(ConfigurationNodeApi.updateNodeAct(formModel))
6072 if (err) return 5830 if (err) return
6073 UseLayUi.successMsg() 5831 UseLayUi.successMsg()
@@ -6555,6 +6313,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -6555,6 +6313,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6555 }, 6313 },
6556 type: event.data.type, 6314 type: event.data.type,
6557 }; 6315 };
  6316 + await to(autoSaveGraphInfo())
6558 const [err, res] = await to(ConfigurationNodeApi.updateNodeEvent(formModal)) 6317 const [err, res] = await to(ConfigurationNodeApi.updateNodeEvent(formModal))
6559 if (err) return 6318 if (err) return
6560 UseLayUi.successMsg() 6319 UseLayUi.successMsg()
@@ -6748,6 +6507,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -6748,6 +6507,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6748 value: formVal[enumGetValue[formVal[enumConst.ACTION]]], 6507 value: formVal[enumGetValue[formVal[enumConst.ACTION]]],
6749 }, 6508 },
6750 } 6509 }
  6510 + await to(autoSaveGraphInfo())
6751 const [err] = await to(ConfigurationNodeApi.updateNodeEvent(data)) 6511 const [err] = await to(ConfigurationNodeApi.updateNodeEvent(data))
6752 if (err) return 6512 if (err) return
6753 UseLayUi.successMsg() 6513 UseLayUi.successMsg()
@@ -7051,6 +6811,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -7051,6 +6811,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7051 condition: tableData, 6811 condition: tableData,
7052 type: event.data.type, 6812 type: event.data.type,
7053 } 6813 }
  6814 + await to(autoSaveGraphInfo())
7054 const [err, res] = await to(ConfigurationNodeApi.updateNodeAct(formModel)) 6815 const [err, res] = await to(ConfigurationNodeApi.updateNodeAct(formModel))
7055 if (err) return 6816 if (err) return
7056 UseLayUi.successMsg() 6817 UseLayUi.successMsg()
@@ -7360,6 +7121,296 @@ DataFormatPanel.prototype.addDataFont = function (container) { @@ -7360,6 +7121,296 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7360 return { component, getValue, componentId, componentFilter, echoDataSource } 7121 return { component, getValue, componentId, componentFilter, echoDataSource }
7361 } 7122 }
7362 7123
  7124 + /**
  7125 + * @description 生成上传弹出层组件
  7126 + */
  7127 + function generatorUploadLayerComponent(callback) {
  7128 +
  7129 + const enumActionEl = {
  7130 + /**
  7131 + * @description 图片选中区域节点
  7132 + */
  7133 + IMG_SELECT_CONTAINER_EL: 'imgSelectContainerEl',
  7134 +
  7135 + /**
  7136 + * @description 切换图片来源控制
  7137 + */
  7138 + SWITCH_IMG_ORIGIN_FILTER: 'switchImgOriginFilter',
  7139 +
  7140 + /**
  7141 + * @description 图片选中侧边栏节点
  7142 + */
  7143 + VAR_IMG_CONTAINER_SIDEBAR: 'var-image__container-sidebar',
  7144 +
  7145 + /**
  7146 + * @description 图库图形选择区域
  7147 + */
  7148 + VAR_IMG_CONTAINER_CONTENT: 'var-image__container-content',
  7149 +
  7150 + /**
  7151 + * @description 图库图形项
  7152 + */
  7153 + VAR_IMG_ITEM: 'var-image__img-item',
  7154 +
  7155 + /**
  7156 + * @description 图库图形选中控制
  7157 + */
  7158 + VAR_IMG_ITEM_CHECKED: 'var-image__img-item--checked',
  7159 +
  7160 + /**
  7161 + * @description 图库图形类别节点
  7162 + */
  7163 + VAR_IMG_CATEGORY: 'var-image__category',
  7164 +
  7165 + /**
  7166 + * @description 图库图形类别选择状态
  7167 + */
  7168 + VAR_IMG_CATEGORY_CHECKED: 'var-image__category--checked',
  7169 +
  7170 + /**
  7171 + * @description 本地上传图片节点
  7172 + */
  7173 + UPLOAD_LOCAL_FILE_EL: 'var-image__container--local',
  7174 +
  7175 + /**
  7176 + * @description 本地上传图片状态
  7177 + */
  7178 + IMAGE_UPLOAD_STATE_EL: 'var-image__upload-state',
  7179 +
  7180 + /**
  7181 + * @description 预览图片状态
  7182 + */
  7183 + IMAGE_PREVIEW_EL: 'preview__img--preview',
  7184 +
  7185 + /**
  7186 + * @description 本地图片上传删除按钮
  7187 + */
  7188 + IMAGE_DEL_PREVIEW_EL: 'var-image__del-icon',
  7189 + }
  7190 +
  7191 + const enumConst = {
  7192 + /**
  7193 + * @description 图片来源
  7194 + */
  7195 + IMAGE_ORIGIN: 'imageOrigin',
  7196 +
  7197 + /**
  7198 + * @description 图库图形类别
  7199 + */
  7200 + IMAGE_GALLERY_CATEGORY: 'category',
  7201 +
  7202 + /**
  7203 + * @description 图表图形路径
  7204 + */
  7205 + IMAGE_GALLERY_IMAGE_PATH: 'imagePath',
  7206 + }
  7207 +
  7208 + /**
  7209 + * @description 图片来源枚举类型
  7210 + */
  7211 + const enumImageOriginType = {
  7212 + LOCAL: 'local',
  7213 + GALLERY: 'gallery',
  7214 + }
  7215 +
  7216 + let imageState = {}
  7217 +
  7218 + /**
  7219 + * @description 设置选中样式
  7220 + * @param event
  7221 + * @param nodeClass
  7222 + * @param styleClass
  7223 + */
  7224 + function setImageSelectedStyle(event, nodeClass, styleClass) {
  7225 + if (!$(event.target).hasClass(nodeClass)) return
  7226 + $(`.${nodeClass}`).each(function () {
  7227 + $(this).removeClass(styleClass)
  7228 + })
  7229 + $(event.target).addClass(styleClass)
  7230 + }
  7231 +
  7232 + /**
  7233 + * @description 切换图库图形
  7234 + * @param event
  7235 + */
  7236 + function switchGalleryLib(event) {
  7237 + const key = $(event.target).attr(enumConst.IMAGE_GALLERY_CATEGORY)
  7238 + const category = sidebarInstance.getVariableImageLib(key)
  7239 + if (key && category) {
  7240 + $(`#${enumActionEl.VAR_IMG_CONTAINER_CONTENT}`).html(
  7241 + category.lib.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_ITEM}" title="${next.name}"><img src="${next.staticPath}" alt=""></div>`, ''),
  7242 + )
  7243 + }
  7244 + }
  7245 +
  7246 + /**
  7247 + * @description 图片来源事件监听
  7248 + */
  7249 + function generatorSelectImgEventListener() {
  7250 + $(`#${enumActionEl.VAR_IMG_CONTAINER_CONTENT}`).on('click', event => {
  7251 + setImageSelectedStyle(event, enumActionEl.VAR_IMG_ITEM, enumActionEl.VAR_IMG_ITEM_CHECKED)
  7252 + imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = $(event.target).find('img').attr('src')
  7253 + })
  7254 + $(`#${enumActionEl.VAR_IMG_CONTAINER_SIDEBAR}`).on('click', event => {
  7255 + setImageSelectedStyle(event, enumActionEl.VAR_IMG_CATEGORY, enumActionEl.VAR_IMG_CATEGORY_CHECKED)
  7256 + imageState[enumConst.IMAGE_GALLERY_CATEGORY] = $(event.target).attr(enumConst.IMAGE_GALLERY_CATEGORY)
  7257 + imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = null
  7258 + switchGalleryLib(event)
  7259 + })
  7260 + }
  7261 +
  7262 +
  7263 + /**
  7264 + * @description 创建本地图片上传区域
  7265 + */
  7266 + function createLocalFileContainer() {
  7267 + return `
  7268 + <div id="${enumActionEl.UPLOAD_LOCAL_FILE_EL}" class="layui-upload">
  7269 + <div class="preview__img">
  7270 + <img src="" class="layui-upload-img" id="${enumActionEl.IMAGE_PREVIEW_EL}">
  7271 + <div class="var_image__add-icon">+</div>
  7272 + <div class="var-image__del-icon">x</div>
  7273 + </div>
  7274 + <div class="layui-upload-list"></div>
  7275 + </div>
  7276 + <div id="${enumActionEl.IMAGE_UPLOAD_STATE_EL}"></div>
  7277 + <div style="margin-top: 30px;">图片格式支持png、jpg(jpeg)、gif, 大小不能超过5M</div>
  7278 + `
  7279 + }
  7280 +
  7281 + /**
  7282 + * @description 创建图库图形上传区域
  7283 + */
  7284 + function createGalleryFileContainer() {
  7285 + const category = sidebarInstance.getAllVariableImageLib()
  7286 + const defaultShow = category[0] || { lib: [] }
  7287 + return `
  7288 + <div class="var-image__container--gallery">
  7289 + <div id="${enumActionEl.VAR_IMG_CONTAINER_SIDEBAR}">
  7290 + ${category.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_CATEGORY}" ${enumConst.IMAGE_GALLERY_CATEGORY}="${next.key}">${next.label}</div>`, '')}
  7291 + </div>
  7292 + <div id="${enumActionEl.VAR_IMG_CONTAINER_CONTENT}">
  7293 + ${defaultShow.lib.reduce((prev, next) => prev + `<div class="${enumActionEl.VAR_IMG_ITEM}" title="${next.name}"><img src="${next.staticPath}" alt=""></div>`, '')}
  7294 + </div>
  7295 + </div>
  7296 + `
  7297 + }
  7298 +
  7299 + /**
  7300 + * @description 上传
  7301 + */
  7302 + function uploadFileEvent() {
  7303 + $(`.${enumActionEl.IMAGE_DEL_PREVIEW_EL}`).on('click', (event) => {
  7304 + event.stopPropagation()
  7305 + $(`#${enumActionEl.IMAGE_PREVIEW_EL}`).attr('src', '')
  7306 + imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = null
  7307 + })
  7308 + upload.render({
  7309 + elem: `#${enumActionEl.UPLOAD_LOCAL_FILE_EL}`,
  7310 + auto: false,
  7311 + size: 1024 * 5,
  7312 + url: '/yt/oss/upload',
  7313 + method: 'post',
  7314 + choose(obj) {
  7315 + obj.preview(async function (index, file, result) {
  7316 + const formData = new FormData()
  7317 + formData.set('file', file)
  7318 + const [err, res] = await to(ConfigurationNodeApi.uploadImg(formData))
  7319 + if (!err) {
  7320 + $(`#${enumActionEl.IMAGE_PREVIEW_EL}`).attr('src', result)
  7321 + const { fileStaticUri = '' } = res
  7322 + imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH] = fileStaticUri
  7323 + }
  7324 + });
  7325 + },
  7326 + });
  7327 + }
  7328 +
  7329 + /**
  7330 + * @description 切换
  7331 + */
  7332 + function switchUploadImgTypeEventListener() {
  7333 + form.on(`radio(${enumActionEl.SWITCH_IMG_ORIGIN_FILTER})`, event => {
  7334 + const { value } = event
  7335 + console.log('event', event)
  7336 + imageState = {}
  7337 + if (value === enumImageOriginType.LOCAL) {
  7338 + $(`#${enumActionEl.IMG_SELECT_CONTAINER_EL}`).html(createLocalFileContainer())
  7339 + imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.LOCAL
  7340 + uploadFileEvent()
  7341 + } else if (value === enumImageOriginType.GALLERY) {
  7342 + $(`#${enumActionEl.IMG_SELECT_CONTAINER_EL}`).html(createGalleryFileContainer())
  7343 + const defaultChecked = $(`.${enumActionEl.VAR_IMG_CATEGORY}`).eq(0)
  7344 + defaultChecked.addClass(enumActionEl.VAR_IMG_CATEGORY_CHECKED)
  7345 + imageState[enumConst.IMAGE_GALLERY_CATEGORY] = defaultChecked.attr(enumConst.IMAGE_GALLERY_CATEGORY)
  7346 + imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.GALLERY
  7347 + generatorSelectImgEventListener()
  7348 + }
  7349 + })
  7350 + }
  7351 +
  7352 +
  7353 + /**
  7354 + * @description 初始化并设置默认值
  7355 + */
  7356 + function initSelectImg() {
  7357 + switchUploadImgTypeEventListener()
  7358 + uploadFileEvent()
  7359 + imageState[enumConst.IMAGE_ORIGIN] = enumImageOriginType.LOCAL
  7360 + form.render()
  7361 + }
  7362 +
  7363 + /**
  7364 + * @description 创建上传图片layer
  7365 + */
  7366 + function createUploadImgLayer() {
  7367 + const content = `
  7368 + <div class="layui-form">
  7369 + <div class="layui-form-item">
  7370 + <div class="var-image__radio">
  7371 + <input type="radio" lay-filter="${enumActionEl.SWITCH_IMG_ORIGIN_FILTER}" name="${enumConst.IMAGE}" value="${enumImageOriginType.LOCAL}" title="本地图片" checked="">
  7372 + <input type="radio" lay-filter="${enumActionEl.SWITCH_IMG_ORIGIN_FILTER}" name="${enumConst.IMAGE}" value="${enumImageOriginType.GALLERY}" title="图库图形">
  7373 + </div>
  7374 + </div>
  7375 + </div>
  7376 + <div id="${enumActionEl.IMG_SELECT_CONTAINER_EL}">
  7377 + ${createLocalFileContainer()}
  7378 + </div>
  7379 + `
  7380 +
  7381 + layer.open({
  7382 + title: '图片',
  7383 + type: 1,
  7384 + content,
  7385 + skin: 'event-layer__override',
  7386 + area: '600px',
  7387 + btn: ["应用", "取消"],
  7388 + shade: ["0.7", "#fafafa"],
  7389 + yes(index) {
  7390 + layer.close(index)
  7391 + if (callback && typeof callback === 'function') callback(imageState)
  7392 + },
  7393 + but2(index, layero) {
  7394 + imageState = {}
  7395 + layer.close(index)
  7396 + },
  7397 + zIndex: layer.zIndex,
  7398 + async success(layero, index) {
  7399 + layer.setTop(layero);
  7400 + $(layero).addClass('layui-form').find('.layui-layer-btn0').attr({
  7401 + 'lay-submit': '',
  7402 + 'lay-filter': enumActionEl.IMAGE_LAYER_FILTER,
  7403 + })
  7404 + initSelectImg()
  7405 + },
  7406 + })
  7407 + }
  7408 +
  7409 + createUploadImgLayer()
  7410 +
  7411 + return { record: imageState }
  7412 + }
  7413 +
7363 // 异步设置此处才能生效 -- 设置默认select和样式和初始化侧边栏生成组件和事件绑定 7414 // 异步设置此处才能生效 -- 设置默认select和样式和初始化侧边栏生成组件和事件绑定
7364 setTimeout(() => { 7415 setTimeout(() => {
7365 7416
@@ -12906,22 +12957,3 @@ function RAFSetInterval(callback, time) { @@ -12906,22 +12957,3 @@ function RAFSetInterval(callback, time) {
12906 } 12957 }
12907 12958
12908 12959
12909 -function globalInit() {  
12910 - init()  
12911 -  
12912 - function init() {  
12913 - initRealTime()  
12914 - }  
12915 -  
12916 - function initRealTime() {  
12917 - RAFSetInterval(() => {  
12918 - const allTimeNode = document.querySelectorAll('.thingKit-component__real-time .real-time__now')  
12919 - for (const time of allTimeNode) {  
12920 - const date = new Date()  
12921 - time.innerHTML = `${date.getHours() < 10 ? '0' : ''}${date.getHours()}:${date.getMinutes() < 10 ? '0' : ''}${date.getMinutes()}:${date.getSeconds() < 10 ? '0' : ''}${date.getSeconds()}`  
12922 - }  
12923 - }, 1000)  
12924 - }  
12925 -}  
12926 -  
12927 -globalInit()