Commit bd166a401f05faff8a8865ddd605459fd9ddab14

Authored by ww
2 parents 128aa52d 72904cc9

perf: hide cell outside arrow

... ... @@ -36,6 +36,15 @@ class ConfigurationNodeApi {
36 36 }
37 37
38 38 /**
  39 + * @description 获取所有的网关设备和直连设备
  40 + * @param {string} orgId
  41 + * @returns
  42 + */
  43 + static getAllGatewayDeviceAndConnectionDevice(orgId) {
  44 + return defHttp.get(`/yt/device/list/master/${orgId}`)
  45 + }
  46 +
  47 + /**
39 48 * @description 查询设备的子设备
40 49 * @param deviceId 设备ID
41 50 * @returns {Promise<*>}
... ...
... ... @@ -6021,9 +6021,9 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6021 6021 /**
6022 6022 * @description 创建回显数据 查询出所有网关设备和直连设备
6023 6023 */
6024   - async function getMaterDevice() {
  6024 + async function getAllGatewayDeviceAndConnectionDevice() {
6025 6025 if (!orgId) return
6026   - const [err, res] = await to(ConfigurationNodeApi.getMasterDevice(orgId))
  6026 + const [err, res] = await to(ConfigurationNodeApi.getAllGatewayDeviceAndConnectionDevice(orgId))
6027 6027 allDeviceOptions = res
6028 6028 mountAllDeviceToSelect()
6029 6029 }
... ... @@ -6072,7 +6072,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6072 6072 onlyIconControl: true,
6073 6073 click(node) {
6074 6074 orgId = node.data.id
6075   - getMaterDevice()
  6075 + getAllGatewayDeviceAndConnectionDevice()
6076 6076 },
6077 6077 },
6078 6078 })
... ... @@ -6091,9 +6091,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6091 6091 <select name="${enumConst.DEVICE}" lay-filter="${enumConst.DEVICE}" lay-verType="tips" lay-verify="required"></select>
6092 6092 </td>
6093 6093 <td>
6094   - <select name="${enumConst.SLAVE_DEVICE}" lay-filter="${enumConst.SLAVE_DEVICE}" lay-verType="tips"></select>
6095   - </td>
6096   - <td>
6097 6094 <form action="" style="display: flex">
6098 6095 <div class="override__radio-default">
6099 6096 <input id="${getRowFilter(addRowNumber)}${sendInstructionWay.ONE_WAR}" type="radio" name="${enumConst.WAY}" lay-ignore value="${sendInstructionWay.ONE_WAR}" title="单向" checked="">
... ... @@ -6123,51 +6120,12 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6123 6120 addRowNumber++
6124 6121 }
6125 6122
6126   - /**
6127   - * @description 更新变量选项
6128   - */
6129   - async function updateVariableOptions(data) {
6130   - if (!data.value) return
6131   - const [err, res] = await to(ConfigurationNodeApi.getDeviceAttr(data.value))
6132   - if (!res) return
6133   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: res })
6134   - $(data.elem).parents('tr').find(`select[name="${enumConst.ATTR}"]`).html(generateOption)
6135   - form.render('select')
6136   - }
6137   -
6138   - /**
6139   - * @description 选择设备监听事件
6140   - */
6141   - function createSelectDeviceListenEvent() {
6142   - form.on(`select(${enumConst.DEVICE})`, async (data) => {
6143   - const filter = $(data.elem).parents('tr').attr('lay-filter')
6144   - form.val(filter, {
6145   - [enumConst.SLAVE_DEVICE]: null,
6146   - })
6147   - const isGATEWAY = allDeviceOptions.find(item => item.id === data.value)?.deviceType === "GATEWAY"
6148   - // 网关设备请求子设备
6149   - $(data.elem).parents('tr').find(`select[name="${enumConst.SLAVE_DEVICE}"]`).attr('lay-verify', '')
6150   - if (orgId && isGATEWAY && data.value) {
6151   - const [err, res] = await to(ConfigurationNodeApi.getSlaveDevice(orgId, data.value))
6152   - if (!res) return
6153   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: res })
6154   - $(data.elem).parents('tr').find(`select[name="${enumConst.SLAVE_DEVICE}"]`).attr('lay-verify', 'required').html(generateOption)
6155   - }
6156   - // else {
6157   - // updateVariableOptions(data)
6158   - // }
6159   - UseLayUi.nextTick(() => form.render(`select`, filter))
6160   - })
6161   - // form.on(`select(${ enumConst.SLAVE_DEVICE })`, (data) => {
6162   - // updateVariableOptions(data)
6163   - // })
6164   - }
6165 6123
6166 6124 /**
6167 6125 * @description 删除行
6168 6126 */
6169 6127 function createDeleteRowListenEvent() {
6170   - $(`.${enumActionEl.DEL_ROW_EL}`).on('click', (event) => {
  6128 + $(`#${enumActionEl.DEVICE_DATA_BODY_EL}`).on('click', `.${enumActionEl.DEL_ROW_EL}`, (event) => {
6171 6129 // $(event.target).parents('tr').find('editor')
6172 6130 $(event.target).parents('tr').remove()
6173 6131 })
... ... @@ -6181,7 +6139,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6181 6139 addRecord()
6182 6140 const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions })
6183 6141 $(`#${enumActionEl.DEVICE_DATA_BODY_EL} tr`).last().find(`select[name="${enumConst.DEVICE}"]`).html(generateOption)
6184   - createDeleteRowListenEvent()
6185 6142 form.render('select')
6186 6143 })
6187 6144 }
... ... @@ -6195,48 +6152,40 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6195 6152 }
6196 6153
6197 6154 /**
6198   - * @description 生成事件监听
6199   - */
6200   - function generatorEventListen() {
6201   - createSelectDeviceListenEvent()
6202   - createDeleteRowListenEvent()
6203   - createAddRowListenEvent()
6204   - }
6205   -
6206   - /**
6207   - * @description 挂载选项 根据行号 key 挂载option
6208   - * @param row 行号
6209   - * @param key select name
6210   - * @param data 数据源
6211   - */
6212   - function mountSelectOptions(row, key, data) {
6213   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: data })
6214   - $(`#${enumActionEl.DEVICE_DATA_BODY_EL}`).find(`tr[lay-filter="${getRowFilter(row)}"] select[name="${key}"]`).html(generateOption)
6215   - }
6216   -
6217   - /**
6218   - * @description 根据主设备ID获取从设备
  6155 + * @description 下拉选项挂载
6219 6156 */
6220   - async function getSlaveDeviceByMasterDevice(deviceId, row) {
6221   - const res = await ConfigurationNodeApi.getSlaveDevice(orgId, deviceId)
6222   - mountSelectOptions(row, enumConst.SLAVE_DEVICE, res)
  6157 + function createSelectOptionMountEvent(params) {
  6158 + $(`#${enumActionEl.DEVICE_DATA_BODY_EL}`).on('click', '.layui-form-select', event => {
  6159 + const width = event.currentTarget.offsetWidth || 200
  6160 + const height = event.currentTarget.offsetHeight || 38
  6161 + const offset = $(event.currentTarget).offset()
  6162 + $(event.currentTarget).find('dl').css({
  6163 + position: 'fixed',
  6164 + 'min-width': width + 'px',
  6165 + top: offset.top + height + 'px',
  6166 + left: offset.left + 'px'
  6167 + })
  6168 + })
6223 6169 }
6224 6170
6225 6171 /**
6226   - * @description 根据设备ID获取设备属性
  6172 + * @description 生成事件监听
6227 6173 */
6228   - async function getDeviceAttrByDeviceId(deviceId, row) {
6229   - const res = await ConfigurationNodeApi.getDeviceAttr(deviceId)
6230   - mountSelectOptions(row, enumConst.ATTR, res)
  6174 + function generatorEventListen() {
  6175 + createDeleteRowListenEvent()
  6176 + createAddRowListenEvent()
  6177 + createSelectOptionMountEvent()
6231 6178 }
6232 6179
6233 6180 /**
6234 6181 * @description 回显表单数据
6235 6182 */
6236 6183 function echoFormData(info) {
6237   - const { content: { data = [] } = {} } = info
6238   - data.forEach((datum, index) => echoEachData(datum, index))
6239   - mountAllDeviceToSelect()
  6184 + const { content: { data = [] } = {}, orgId } = info
  6185 + data.forEach((datum, index) => {
  6186 + addRecord(datum)
  6187 + form.val(getRowFilter(index), datum)
  6188 + })
6240 6189 }
6241 6190
6242 6191 /**
... ... @@ -6245,33 +6194,17 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6245 6194 function echoOrgTree(id) {
6246 6195 orgId = id
6247 6196 const node = UseLayUi.findTreeObjectByField(treeList, id)
6248   - $(`#${enumActionEl.ORG_EL}`).find(`input[name="${enumConst.ORG_ID}"]`).val(orgId).parent().find('span').html(node?.name)
  6197 + orgId = id
  6198 + $(`#${enumActionEl.ORG_EL}`)
  6199 + .find(`input[name="${enumConst.ORG_ID}"]`).val(orgId).parent()
  6200 + .find('span').html(node?.name)
6249 6201 }
6250 6202
6251 6203 /**
6252   - * @description 回显每条数据
  6204 + * @description 判断是否为正确的JSON结构
  6205 + * @param {string} string
  6206 + * @returns
6253 6207 */
6254   - function echoEachData(datum = {}, row) {
6255   - addRecord(datum)
6256   - const deviceId = datum[enumConst.DEVICE]
6257   - const slaveDeviceId = datum[enumConst.SLAVE_DEVICE]
6258   - const queue = []
6259   -
6260   - if (slaveDeviceId) {
6261   - queue.push(() => getSlaveDeviceByMasterDevice(deviceId, row))
6262   - // queue.push(() => getDeviceAttrByDeviceId(slaveDeviceId, row))
6263   - }
6264   - // else {
6265   - // queue.push(() => getDeviceAttrByDeviceId(deviceId, row))
6266   - // }
6267   -
6268   - Promise
6269   - .all(queue.map(item => item()))
6270   - .finally(() => {
6271   - form.val(getRowFilter(row), datum)
6272   - })
6273   - }
6274   -
6275 6208 function isJson(string) {
6276 6209 if (typeof string === 'string') {
6277 6210 try {
... ... @@ -6368,7 +6301,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6368 6301 <thead>
6369 6302 <tr>
6370 6303 <th style="text-align:center">选择设备</th>
6371   - <th style="text-align:center">选择子设备</th>
6372 6304 <th style="text-align:center">单向 / 双向</th>
6373 6305 <th style="text-align:center">下发值</th>
6374 6306 <th style="text-align:center">操作</th>
... ... @@ -6410,10 +6342,10 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6410 6342 const info = getLayerBindInfo('event', type)
6411 6343 const { content: { data = [] } = {}, orgId } = info
6412 6344 echoOrgTree(orgId)
  6345 + await getAllGatewayDeviceAndConnectionDevice()
6413 6346 if (!info || !data.length) {
6414 6347 addRecord()
6415 6348 } else {
6416   - await getMaterDevice()
6417 6349 echoFormData(info)
6418 6350 }
6419 6351 generatorEventListen()
... ... @@ -6728,7 +6660,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6728 6660 function createAddRowListenEvent() {
6729 6661 $(`#${enumActionEl.ADD_BTN_EL}`).on('click', () => {
6730 6662 addRecord()
6731   - createDeleteRowListenEvent()
6732 6663 })
6733 6664 }
6734 6665
... ... @@ -6736,7 +6667,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6736 6667 * @description 创建删除行事件
6737 6668 */
6738 6669 function createDeleteRowListenEvent() {
6739   - $(`.${enumActionEl.DEL_BTN_EL}`).on('click', (event) => {
  6670 + $(`#${enumActionEl.TABLE_BODY_EL}`).on('click', `.${enumActionEl.DEL_BTN_EL}`, (event) => {
6740 6671 $(event.target).parents('tr').remove()
6741 6672 })
6742 6673 }
... ...
... ... @@ -5497,7 +5497,9 @@ HoverIcons.prototype.createArrow = function(img, tooltip, direction)
5497 5497 }
5498 5498 }));
5499 5499
5500   - return arrow;
  5500 + // TODO thingsKit 隐藏cell四周的箭头
  5501 + return document.createElement('div');
  5502 + // return arrow;
5501 5503 };
5502 5504
5503 5505 /**
... ...