Commit e027bfdb272d8d1b97b773ca1f4e83702b569b9f
1 parent
b7006e3e
fix: bind data source use new fetch api
Showing
2 changed files
with
152 additions
and
126 deletions
... | ... | @@ -181,4 +181,32 @@ class ConfigurationNodeApi { |
181 | 181 | static getDeviceAttribute(deviceProfileId, dataType) { |
182 | 182 | return defHttp.get(`/yt/device/attributes/${deviceProfileId}`, { params: { dataType } }) |
183 | 183 | } |
184 | + | |
185 | + /** | |
186 | + * @description 获取产品 | |
187 | + * @param {string} deviceType | |
188 | + * @returns | |
189 | + */ | |
190 | + static getProduct(deviceType) { | |
191 | + return defHttp.get('/yt/device_profile/me/list', { params: { deviceType } }) | |
192 | + } | |
193 | + | |
194 | + /** | |
195 | + * @description 获取满足条件的设备 | |
196 | + * @param {{deviceLabel: string, deviceProfileId: string, deviceType: string, organizationId: string }} params | |
197 | + * @returns | |
198 | + */ | |
199 | + static getMeetConditionsDevice(params = {}) { | |
200 | + const { deviceLabel, deviceProfileId, deviceType, organizationId } = params | |
201 | + return defHttp.get('/yt/device/list', { params: { deviceLabel, deviceProfileId, deviceType, organizationId } }) | |
202 | + } | |
203 | + | |
204 | + /** | |
205 | + * @description 获取字典值 | |
206 | + * @param {string} dictCode | |
207 | + * @returns | |
208 | + */ | |
209 | + static getDictionaryValue(dictCode) { | |
210 | + return defHttp.post('/yt/dict_item/find', {dictCode}) | |
211 | + } | |
184 | 212 | } | ... | ... |
... | ... | @@ -4952,12 +4952,6 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
4952 | 4952 | let treeList = [] |
4953 | 4953 | |
4954 | 4954 | /** |
4955 | - * @description 当前选中的组织树节点 | |
4956 | - * @type {null | string} | |
4957 | - */ | |
4958 | - let currentCheckedOrgNode = null | |
4959 | - | |
4960 | - /** | |
4961 | 4955 | * @description 当前节点绑定数据 |
4962 | 4956 | * @type {null | {act: [], event: [], dataSources: []}} |
4963 | 4957 | */ |
... | ... | @@ -5067,7 +5061,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5067 | 5061 | SLAVE_DEVICE_ID: 'slaveDeviceId', |
5068 | 5062 | ATTR: 'attr', |
5069 | 5063 | GATEWAY: 'GATEWAY', |
5070 | - ADDITIONAL: 'additional' | |
5064 | + ADDITIONAL: 'additional', | |
5065 | + DEVICE_PROFILE_ID: 'deviceProfileId', | |
5066 | + DEVICE_TYPE: 'deviceType' | |
5071 | 5067 | } |
5072 | 5068 | |
5073 | 5069 | /** |
... | ... | @@ -5078,7 +5074,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5078 | 5074 | |
5079 | 5075 | /** |
5080 | 5076 | * @description 用于在其他位置获取数据源绑定的数据,在生成数据源面板中进行了改写 |
5081 | - * @return {{orgId: string, attr: string, deviceId: string, slaveDeviceId: string}} | |
5077 | + * @return {{orgId: string, attr: string, deviceId: string, deviceType: string, deviceProfileId: string}} | |
5082 | 5078 | */ |
5083 | 5079 | function getDataSourceBindValue() { |
5084 | 5080 | |
... | ... | @@ -5236,7 +5232,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5236 | 5232 | |
5237 | 5233 | |
5238 | 5234 | async function mount() { |
5239 | - const { component, echoDataSource, getValue } = generateDataSourceComponent({ validate: false }) | |
5235 | + const { component, echoDataSource, getValue } = generateDataSourceComponent({ validate: true }) | |
5240 | 5236 | $(fragment).append(title).append(component) |
5241 | 5237 | $(container).append(fragment) |
5242 | 5238 | |
... | ... | @@ -5938,7 +5934,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5938 | 5934 | const type = graph.getAttributeForCell(cell, basicAttr.COMPONENT_TYPE) |
5939 | 5935 | return renderMapping[type]?.(field) || {} |
5940 | 5936 | |
5941 | - function getSubmitValue(field) { | |
5937 | + function getSubmitValue(field) { | |
5942 | 5938 | const ENABLED_FLAG = 'on' |
5943 | 5939 | const additionalKey = HandleDataSource.enumConst |
5944 | 5940 | const value = { |
... | ... | @@ -5950,7 +5946,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5950 | 5946 | [enumCategory.DATA_SOURCE]: { |
5951 | 5947 | [enumDataSourceConst.ORG_ID]: field[enumDataSourceConst.ORG_ID], |
5952 | 5948 | [enumDataSourceConst.DEVICE_ID]: field[enumDataSourceConst.DEVICE_ID], |
5953 | - [enumDataSourceConst.SLAVE_DEVICE_ID]: field[enumDataSourceConst.SLAVE_DEVICE_ID] ? field[enumDataSourceConst.SLAVE_DEVICE_ID] : '', | |
5949 | + [enumDataSourceConst.DEVICE_TYPE]: field[enumDataSourceConst.DEVICE_TYPE], | |
5950 | + [enumDataSourceConst.DEVICE_PROFILE_ID]: field[enumDataSourceConst.DEVICE_PROFILE_ID], | |
5954 | 5951 | [enumDataSourceConst.ATTR]: field[enumDataSourceConst.ATTR], |
5955 | 5952 | [enumDataSourceConst.ADDITIONAL]: field[additionalKey.DATA_TYPE] ? { |
5956 | 5953 | [additionalKey.AGG]: field[additionalKey.AGG], |
... | ... | @@ -5994,7 +5991,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5994 | 5991 | [enumCategory.DATA_SOURCE]: { |
5995 | 5992 | [enumDataSourceConst.ORG_ID]: field[enumDataSourceConst.ORG_ID], |
5996 | 5993 | [enumDataSourceConst.DEVICE_ID]: field[enumDataSourceConst.DEVICE_ID], |
5997 | - [enumDataSourceConst.SLAVE_DEVICE_ID]: field[enumDataSourceConst.SLAVE_DEVICE_ID] ? field[enumDataSourceConst.SLAVE_DEVICE_ID] : '', | |
5994 | + [enumDataSourceConst.DEVICE_TYPE]: field[enumDataSourceConst.DEVICE_TYPE], | |
5995 | + [enumDataSourceConst.DEVICE_PROFILE_ID]: field[enumDataSourceConst.DEVICE_PROFILE_ID], | |
5998 | 5996 | [enumDataSourceConst.ATTR]: field[enumDataSourceConst.ATTR], |
5999 | 5997 | [enumDataSourceConst.ADDITIONAL]: { |
6000 | 5998 | [additionalKey.ORG_NAME]: field[additionalKey.ORG_NAME], |
... | ... | @@ -7765,13 +7763,13 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7765 | 7763 | |
7766 | 7764 | const enumDataSourceConst = { |
7767 | 7765 | ORG_ID: 'orgId', |
7766 | + DEVICE_TYPE: 'deviceType', | |
7767 | + DEVICE_PROFILE_ID: 'deviceProfileId', | |
7768 | 7768 | DEVICE_ID: 'deviceId', |
7769 | - SLAVE_DEVICE_ID: 'slaveDeviceId', | |
7770 | 7769 | ATTR: 'attr', |
7771 | 7770 | GATEWAY: 'GATEWAY', |
7772 | 7771 | ORG_NAME: 'orgName', |
7773 | 7772 | DEVICE_NAME: 'deviceName', |
7774 | - SLAVE_DEVICE_NAME: 'slaveDeviceName', | |
7775 | 7773 | ATTR_NAME: 'attrName' |
7776 | 7774 | } |
7777 | 7775 | |
... | ... | @@ -7782,10 +7780,10 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7782 | 7780 | let deviceList = [] |
7783 | 7781 | |
7784 | 7782 | /** |
7785 | - * @description | |
7786 | - * @type {{id: string, deviceType: string, name: string, deviceProfileId: string}[]} | |
7787 | - */ | |
7788 | - let slaveDeviceList = [] | |
7783 | + * @descrition | |
7784 | + * @type {{deviceProfileId: string, id: string, organizationId: string, deviceType: string}} | |
7785 | + */ | |
7786 | + let currentDataSource = {} | |
7789 | 7787 | |
7790 | 7788 | const component = document.createElement('div') |
7791 | 7789 | |
... | ... | @@ -7799,13 +7797,66 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7799 | 7797 | init() |
7800 | 7798 | |
7801 | 7799 | function init() { |
7802 | - generatorOrgTres() | |
7800 | + generateDeviceTypeSelect() | |
7801 | + generateProductSelect() | |
7802 | + generatorOrgTrees() | |
7803 | 7803 | generatorDeviceSelect() |
7804 | - generatorSlaveDevice() | |
7805 | 7804 | generatorAttrSelect() |
7806 | 7805 | generateDeviceNameInput() |
7807 | 7806 | } |
7808 | 7807 | |
7808 | + function generateDeviceTypeSelect() { | |
7809 | + getDeviceType() | |
7810 | + | |
7811 | + const deviceType = UseLayUi.createSelect({ | |
7812 | + label: '设备类型', | |
7813 | + bindValueFiled: enumDataSourceConst.DEVICE_TYPE, | |
7814 | + layFilter: `${componentFilter}--${enumDataSourceConst.DEVICE_TYPE}`, | |
7815 | + className: 'data-source__component-select', | |
7816 | + ...validateRule, | |
7817 | + onClick(data) { | |
7818 | + const { value } = data | |
7819 | + form.val(componentFilter, { | |
7820 | + [enumDataSourceConst.DEVICE_PROFILE_ID]: null, | |
7821 | + [enumDataSourceConst.DEVICE_ID]: null, | |
7822 | + [enumDataSourceConst.DEVICE_NAME]: null, | |
7823 | + [enumDataSourceConst.DEVICE_ID]: null, | |
7824 | + [enumDataSourceConst.ATTR]: null, | |
7825 | + [enumDataSourceConst.ATTR_NAME]: null, | |
7826 | + [enumDataSourceConst.ORG_ID]: null | |
7827 | + }) | |
7828 | + | |
7829 | + currentDataSource[enumDataSourceConst.DEVICE_TYPE] = value | |
7830 | + getMeetConditionsDevice(currentDataSource) | |
7831 | + getProduct(value) | |
7832 | + }, | |
7833 | + }) | |
7834 | + $(component).append(deviceType) | |
7835 | + } | |
7836 | + | |
7837 | + function generateProductSelect() { | |
7838 | + const productSelect = UseLayUi.createSelect({ | |
7839 | + label: '产品', | |
7840 | + bindValueFiled: enumDataSourceConst.DEVICE_PROFILE_ID, | |
7841 | + layFilter: `${componentFilter}--${enumDataSourceConst.DEVICE_PROFILE_ID}`, | |
7842 | + className: 'data-source__component-select', | |
7843 | + ...validateRule, | |
7844 | + onClick(data) { | |
7845 | + const { value } = data | |
7846 | + form.val(componentFilter, { | |
7847 | + [enumDataSourceConst.DEVICE_NAME]: null, | |
7848 | + [enumDataSourceConst.DEVICE_ID]: null, | |
7849 | + [enumDataSourceConst.ATTR]: null, | |
7850 | + [enumDataSourceConst.ATTR_NAME]: null, | |
7851 | + }) | |
7852 | + currentDataSource[enumDataSourceConst.DEVICE_PROFILE_ID] = value | |
7853 | + getMeetConditionsDevice(currentDataSource) | |
7854 | + getAttrByDeviceId(value) | |
7855 | + }, | |
7856 | + }) | |
7857 | + $(component).append(productSelect) | |
7858 | + } | |
7859 | + | |
7809 | 7860 | async function generateDeviceNameInput() { |
7810 | 7861 | const template = ` |
7811 | 7862 | <div class="layui-form-item" style="margin-bottom: 0"> |
... | ... | @@ -7815,38 +7866,35 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7815 | 7866 | <input style="display: none" type="text" name="${enumDataSourceConst.DEVICE_NAME}" class="layui-input"> |
7816 | 7867 | </div> |
7817 | 7868 | <div class="layui-form-item" style="margin-bottom: 0"> |
7818 | - <input style="display: none" type="text" name="${enumDataSourceConst.SLAVE_DEVICE_NAME}" class="layui-input"> | |
7819 | - </div> | |
7820 | - <div class="layui-form-item" style="margin-bottom: 0"> | |
7821 | 7869 | <input style="display: none" type="text" name="${enumDataSourceConst.ATTR_NAME}" class="layui-input"> |
7822 | 7870 | </div> |
7823 | 7871 | ` |
7824 | 7872 | $(component).append(template) |
7825 | 7873 | } |
7826 | 7874 | |
7875 | + async function getDeviceType() { | |
7876 | + const items = await ConfigurationNodeApi.getDictionaryValue('device_type') | |
7877 | + $(`#${componentId} `).find(`select[name="${enumDataSourceConst.DEVICE_TYPE}"]`).html(UseLayUi.generateOptionTemplate({ dataSource: items, labelField: 'itemText', valueField: 'itemValue' })) | |
7878 | + form.render('select', componentFilter) | |
7879 | + } | |
7827 | 7880 | |
7828 | - /** | |
7829 | - * @description 根据组织ID获取设备 | |
7830 | - */ | |
7831 | - async function getDevicesByOrgId(organizationId) { | |
7832 | - if (organizationId) { | |
7833 | - const items = deviceList = await ConfigurationNodeApi.getMasterDevice(organizationId); | |
7834 | - $(`#${componentId} `).find(`select[name="${enumDataSourceConst.DEVICE_ID}"]`).html(UseLayUi.generateOptionTemplate({ dataSource: items })) | |
7835 | - form.render('select', componentFilter) | |
7836 | - } | |
7881 | + async function getProduct(deviceType) { | |
7882 | + const items = productList = await ConfigurationNodeApi.getProduct(deviceType) | |
7883 | + $(`#${componentId} `).find(`select[name="${enumDataSourceConst.DEVICE_PROFILE_ID}"]`).html(UseLayUi.generateOptionTemplate({ dataSource: items, labelField: 'name', valueField: 'id', alias: 'alias' })) | |
7884 | + form.render('select', componentFilter) | |
7837 | 7885 | } |
7838 | 7886 | |
7839 | 7887 | /** |
7840 | - * @description 通过主设备ID获取从设备 | |
7888 | + * @description 根据组织ID获取设备 | |
7841 | 7889 | */ |
7842 | - async function getSlaveDeviceByMasterDeviceId(orgId, deviceId) { | |
7843 | - if (deviceId && currentCheckedOrgNode) { | |
7844 | - const items = slaveDeviceList = await ConfigurationNodeApi.getSlaveDevice(orgId, deviceId); | |
7845 | - $(`#${componentId} `).find(`select[name="${enumDataSourceConst.SLAVE_DEVICE_ID}"]`).html(UseLayUi.generateOptionTemplate({ dataSource: items })) | |
7846 | - form.render('select', componentFilter) | |
7847 | - } | |
7890 | + async function getMeetConditionsDevice(params) { | |
7891 | + if (!params.organizationId) return | |
7892 | + const items = await ConfigurationNodeApi.getMeetConditionsDevice(params); | |
7893 | + $(`#${componentId} `).find(`select[name="${enumDataSourceConst.DEVICE_ID}"]`).html(UseLayUi.generateOptionTemplate({ dataSource: items, valueField: 'tbDeviceId', labelField: 'name' })) | |
7894 | + form.render('select', componentFilter) | |
7848 | 7895 | } |
7849 | 7896 | |
7897 | + | |
7850 | 7898 | /** |
7851 | 7899 | * @description 根据设备ID获取属性 |
7852 | 7900 | */ |
... | ... | @@ -7862,7 +7910,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7862 | 7910 | /** |
7863 | 7911 | * @description 生成组织选择 |
7864 | 7912 | */ |
7865 | - async function generatorOrgTres() { | |
7913 | + async function generatorOrgTrees() { | |
7866 | 7914 | const orgContainerId = `data-source__component--org-${Date.now()}` |
7867 | 7915 | const orgContainer = `<div id="${orgContainerId}"></div>` |
7868 | 7916 | $(component).append(orgContainer) |
... | ... | @@ -7881,18 +7929,15 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7881 | 7929 | treeProps: { |
7882 | 7930 | data: treeList, |
7883 | 7931 | onlyIconControl: true, |
7884 | - click(node) { | |
7885 | - currentCheckedOrgNode = node?.data?.id | |
7932 | + | |
7933 | + click(node) { | |
7886 | 7934 | form.val(componentFilter, { |
7887 | 7935 | [enumDataSourceConst.ORG_NAME]: node?.data?.title, |
7888 | 7936 | [enumDataSourceConst.DEVICE_ID]: null, |
7889 | - [enumDataSourceConst.SLAVE_DEVICE_ID]: null, | |
7890 | - [enumDataSourceConst.ATTR]: null, | |
7891 | 7937 | [enumDataSourceConst.DEVICE_NAME]: null, |
7892 | - [enumDataSourceConst.SLAVE_DEVICE_NAME]: null, | |
7893 | - [enumDataSourceConst.ATTR_NAME]: null, | |
7894 | 7938 | }) |
7895 | - getDevicesByOrgId(node.data.id) | |
7939 | + currentDataSource.organizationId = node?.data?.id | |
7940 | + getMeetConditionsDevice(currentDataSource) | |
7896 | 7941 | }, |
7897 | 7942 | }, |
7898 | 7943 | }) |
... | ... | @@ -7914,50 +7959,15 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7914 | 7959 | if (!selected) return |
7915 | 7960 | form.val(componentFilter, { |
7916 | 7961 | [enumDataSourceConst.DEVICE_NAME]: selected?.name, |
7917 | - [enumDataSourceConst.SLAVE_DEVICE_ID]: null, | |
7918 | 7962 | [enumDataSourceConst.ATTR]: null, |
7919 | - [enumDataSourceConst.SLAVE_DEVICE_NAME]: null, | |
7920 | 7963 | [enumDataSourceConst.ATTR_NAME]: null, |
7921 | 7964 | }) |
7922 | - if (selected.deviceType === enumDataSourceConst.GATEWAY) { | |
7923 | - $(`#${componentId}`).find(`select[name="${enumDataSourceConst.SLAVE_DEVICE_ID}"]`) | |
7924 | - .attr('lay-verify', 'required').attr('lay-verType', 'tips') | |
7925 | - .parentsUntil(`#${componentId}`).show() | |
7926 | - getSlaveDeviceByMasterDeviceId(currentCheckedOrgNode, selected.id) | |
7927 | - } else { | |
7928 | - $(`#${componentId}`).find(`select[name="${enumDataSourceConst.SLAVE_DEVICE_ID}"]`) | |
7929 | - .attr('lay-verify', '').attr('lay-verType', 'tips') | |
7930 | - .parentsUntil(`#${componentId}`).hide() | |
7931 | - console.log(selected) | |
7932 | - getAttrByDeviceId(selected.deviceProfileId) | |
7933 | - } | |
7934 | 7965 | }, |
7935 | 7966 | }) |
7936 | 7967 | $(component).append(deviceSelect) |
7937 | 7968 | } |
7938 | 7969 | |
7939 | - /** | |
7940 | - * @description 生成从设备选择器 | |
7941 | - */ | |
7942 | - function generatorSlaveDevice() { | |
7943 | - const slaveDeviceSelect = UseLayUi.createSelect({ | |
7944 | - label: '子设备', | |
7945 | - bindValueFiled: enumDataSourceConst.SLAVE_DEVICE_ID, | |
7946 | - layFilter: `${componentFilter}--${enumDataSourceConst.SLAVE_DEVICE_ID}`, | |
7947 | - className: 'data-source__component-select', | |
7948 | - onClick(data) { | |
7949 | - const { value } = data | |
7950 | - const selected = slaveDeviceList.find(item => item.id === value) | |
7951 | - form.val(componentFilter, { | |
7952 | - [enumDataSourceConst.SLAVE_DEVICE_NAME]: selected?.name, | |
7953 | - [enumDataSourceConst.ATTR]: null, | |
7954 | - [enumDataSourceConst.ATTR_NAME]: null, | |
7955 | - }) | |
7956 | - getAttrByDeviceId(selected.deviceProfileId) | |
7957 | - }, | |
7958 | - }) | |
7959 | - $(component).append(slaveDeviceSelect) | |
7960 | - } | |
7970 | + | |
7961 | 7971 | |
7962 | 7972 | /** |
7963 | 7973 | * @description 生成属性选择器 |
... | ... | @@ -7984,36 +7994,32 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7984 | 7994 | * @param {{orgId: string, deviceId: string, slaveDeviceId?: string, attr: string}} dataSource |
7985 | 7995 | */ |
7986 | 7996 | function echoDataSource(dataSource = {}) { |
7987 | - const { orgId, deviceId, slaveDeviceId, attr } = dataSource | |
7997 | + const { orgId, deviceId, deviceProfileId, deviceType, attr } = dataSource | |
7988 | 7998 | const queue = [] |
7989 | - if (orgId) { | |
7990 | - currentCheckedOrgNode = orgId | |
7991 | - queue.push(getDevicesByOrgId(orgId)) | |
7992 | - } | |
7993 | - if (slaveDeviceId) { | |
7994 | - queue.push(getSlaveDeviceByMasterDeviceId(orgId, deviceId)) | |
7995 | - $(`#${componentId}`).find(`select[name="${enumDataSourceConst.SLAVE_DEVICE_ID}"]`).parentsUntil(`#${componentId}`).show() | |
7996 | - queue.push(getAttrByDeviceId(slaveDeviceId)) | |
7997 | - } else { | |
7998 | - $(`#${componentId}`).find(`select[name="${enumDataSourceConst.SLAVE_DEVICE_ID}"]`).parentsUntil(`#${componentId}`).hide() | |
7999 | - queue.push(getAttrByDeviceId(deviceId)) | |
8000 | - } | |
7999 | + currentDataSource = { organizationId: orgId, deviceProfileId, deviceType } | |
8000 | + queue.push(getProduct(deviceType)) | |
8001 | + queue.push(getMeetConditionsDevice({ organizationId: orgId, deviceProfileId, deviceType })) | |
8002 | + queue.push(getAttrByDeviceId(deviceProfileId)) | |
8001 | 8003 | Promise.all(queue) |
8002 | 8004 | .finally(() => { |
8003 | - const orgNode = UseLayUi.findTreeObjectByField(treeList, currentCheckedOrgNode) | |
8004 | - $(`#${componentId} input[name="${enumDataSourceConst.ORG_ID}"]`).parent().find('span').html(orgNode?.name) | |
8005 | + const orgNode = UseLayUi.findTreeObjectByField(treeList, orgId) | |
8006 | + | |
8007 | + $(`#${componentId} input[name="${enumDataSourceConst.ORG_ID}"]`).val(orgNode?.id).parent().find('span').html(orgNode?.name) | |
8008 | + | |
8005 | 8009 | form.val(componentFilter, { |
8006 | 8010 | orgId, |
8007 | 8011 | deviceId, |
8008 | - slaveDeviceId, | |
8012 | + deviceProfileId, | |
8013 | + deviceType, | |
8009 | 8014 | attr, |
8010 | 8015 | }) |
8016 | + | |
8011 | 8017 | }) |
8012 | 8018 | } |
8013 | 8019 | |
8014 | 8020 | /** |
8015 | 8021 | * |
8016 | - * @returns {{orgId: string, attr: string, deviceId: string, slaveDeviceId: string}} | |
8022 | + * @returns {{orgId: string, attr: string, deviceId: string, devi}} | |
8017 | 8023 | */ |
8018 | 8024 | function getValue() { |
8019 | 8025 | return form.val(componentFilter) |
... | ... | @@ -8445,13 +8451,14 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8445 | 8451 | function proxyFn(fn) { |
8446 | 8452 | return (...args) => { |
8447 | 8453 | const currentDataSource = getDataSourceBindValue() || {} |
8448 | - | |
8449 | - to(ConfigurationNodeApi.updateNodeInfo({ | |
8450 | - configurationId, | |
8451 | - contentId: currentPageId.id, | |
8452 | - nodeId: graphId, | |
8453 | - [enumCategory.DATA_SOURCE]: currentDataSource | |
8454 | - })) | |
8454 | + if (currentDataSource.deviceProfileId && currentDataSource.deviceType && currentDataSource.orgId) { | |
8455 | + to(ConfigurationNodeApi.updateNodeInfo({ | |
8456 | + configurationId, | |
8457 | + contentId: currentPageId.id, | |
8458 | + nodeId: graphId, | |
8459 | + [enumCategory.DATA_SOURCE]: currentDataSource | |
8460 | + })) | |
8461 | + } | |
8455 | 8462 | fn.apply(null, args) |
8456 | 8463 | } |
8457 | 8464 | } |
... | ... | @@ -12303,14 +12310,15 @@ class UseLayUi { |
12303 | 12310 | * @param {boolean} [addPlaceholderOption = true] options.addPlaceholderOption |
12304 | 12311 | * @param {string} [labelField = 'name'] options.labelField |
12305 | 12312 | * @param {string} [valueField = 'name'] options.valueField |
12313 | + * @param {string} [alias] options.alias | |
12306 | 12314 | * @returns {*} |
12307 | 12315 | */ |
12308 | 12316 | static generateOptionTemplate(options) { |
12309 | - const { dataSource = [], addPlaceholderOption = true, labelField = 'name', valueField = 'id' } = options | |
12317 | + const { dataSource = [], addPlaceholderOption = true, labelField = 'name', valueField = 'id', alias } = options | |
12310 | 12318 | let { renderFn } = options |
12311 | 12319 | renderFn = renderFn || ((record) => { |
12312 | 12320 | if (typeof record === 'object') { |
12313 | - return `<option value="${record[valueField]}" ${record.disabled ? 'disabled=""' : ''}>${record[labelField]}</option>` | |
12321 | + return `<option value="${record[valueField]}" ${record.disabled ? 'disabled=""' : ''}>${alias && record[alias] ? record[alias] : record[labelField]}</option>` | |
12314 | 12322 | } else { |
12315 | 12323 | return `<option value="${record}">${record}</option>` |
12316 | 12324 | } |
... | ... | @@ -12456,6 +12464,7 @@ class UseLayUi { |
12456 | 12464 | * @param {boolean} [options.autoFormatDataSource = true] options.autoFormatDataSource |
12457 | 12465 | * @param {string} [options.layVerify] options.layVerify |
12458 | 12466 | * @param {string} [options.layVerType] options.layVerType |
12467 | + * @param {boolean} [options.addPlaceholderOption] options.addPlaceholderOption | |
12459 | 12468 | * @param {Function} [options.treeProps.onReady] options.treeProps.onReady |
12460 | 12469 | */ |
12461 | 12470 | static createTreeSelect(options) { |
... | ... | @@ -12477,6 +12486,7 @@ class UseLayUi { |
12477 | 12486 | childrenField = 'children', |
12478 | 12487 | layVerify, |
12479 | 12488 | layVerType, |
12489 | + addPlaceholderOption | |
12480 | 12490 | } = options |
12481 | 12491 | |
12482 | 12492 | let { data = [], click, onReady } = treeProps |
... | ... | @@ -12518,12 +12528,12 @@ class UseLayUi { |
12518 | 12528 | function mount() { |
12519 | 12529 | // mount select container |
12520 | 12530 | $(elem).html(template) |
12521 | - | |
12522 | - // mount tree | |
12523 | - // UseLayUi.nextTick(() => { | |
12531 | + const treeData = UseLayUi.formatTreeDataSource(data, customSetTree, valueField, labelField, childrenField) | |
12532 | + if (addPlaceholderOption) treeData.unshift({ title: '请选择', id: undefined }) | |
12533 | + // mount tree | |
12524 | 12534 | tree.render({ |
12525 | 12535 | ...treeProps, |
12526 | - ...(autoFormatDataSource ? { data: UseLayUi.formatTreeDataSource(data, customSetTree, valueField, labelField, childrenField) } : {}), | |
12536 | + ...(autoFormatDataSource ? { data: treeData } : {}), | |
12527 | 12537 | elem: $(elem).find('.tree-select__tree-mount'), |
12528 | 12538 | click(node) { |
12529 | 12539 | setValue(node.data) |
... | ... | @@ -12545,22 +12555,10 @@ class UseLayUi { |
12545 | 12555 | layui.stope(e); |
12546 | 12556 | }) |
12547 | 12557 | |
12548 | - // blur | |
12549 | - // $(document) | |
12550 | - // .on("click", function (e) { | |
12551 | - // const target = e.target | |
12552 | - // const parentNode = $(`.${CLASS_NAME} .tree-select__tree-mount`) | |
12553 | - // if (!parentNode) return | |
12554 | - // console.log($.contains(parentNode, target)) | |
12555 | - // // const showClose = UseLayUi.isInNode(parentNode, target, true) | |
12556 | - // // if (showClose) return | |
12557 | - // // $(`.${ SELECT_CLS }`).removeClass("layui-form-selected") | |
12558 | - // }); | |
12559 | - | |
12560 | 12558 | if (UseLayUi.isFunction(onReady)) { |
12561 | 12559 | onReady(setValue) |
12562 | 12560 | } |
12563 | - // }) | |
12561 | + | |
12564 | 12562 | form.render() |
12565 | 12563 | } |
12566 | 12564 | ... | ... |