Commit a9468f6c5c60d92527a85de8ab544d496c3c7cbd

Authored by ww
1 parent d7612c10

perf: variable image component add default image

... ... @@ -5972,46 +5972,20 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5972 5972 * @description
5973 5973 */
5974 5974 DATA_SOURCE_COMP_EL: 'varImgDataSourceEl',
5975   - }
5976   -
5977   - const enumConst = {
5978   -
5979   - /**
5980   - * @description 最小值
5981   - */
5982   - MIN: 'min',
5983   -
5984   - /**
5985   - * @description 最大值
5986   - */
5987   - MAX: 'max',
5988   -
5989   - /**
5990   - * @description 图片字段 key
5991   - */
5992   - IMAGE: 'image',
5993 5975
5994 5976 /**
5995   - * @description 颜色
  5977 + * @description 默认图片
5996 5978 */
5997   - COLOR: 'color',
  5979 + DEFAULT_IMAGE_EL: 'defaultImageEl',
5998 5980
5999 5981 /**
6000   - * @description 图片来源
6001   - */
6002   - IMAGE_ORIGIN: 'imageOrigin',
6003   -
6004   - /**
6005   - * @description 图库图形类别
  5982 + * @description 默认图片filter
6006 5983 */
6007   - IMAGE_GALLERY_CATEGORY: 'category',
6008   -
6009   - /**
6010   - * @description 图表图形路径
6011   - */
6012   - IMAGE_GALLERY_IMAGE_PATH: 'imagePath',
  5984 + DEFAULT_IMAGE_FILTER: 'defaultImageFilter'
6013 5985 }
6014 5986
  5987 + const enumConst = HandleDynamicEffect.enumVarImageConst
  5988 +
6015 5989 let addRowNumber = 0
6016 5990
6017 5991 let getDataSourceValue = () => {
... ... @@ -6030,6 +6004,45 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6030 6004 createDelRowEvent()
6031 6005 createSetImgEvent()
6032 6006 createDelPreviewImgEvent()
  6007 + createSelectDefaultImageEvent()
  6008 + createDelDefaultImageEvent()
  6009 + }
  6010 +
  6011 + /**
  6012 + * @description 选择默认图片
  6013 + */
  6014 + function createSelectDefaultImageEvent() {
  6015 + $(`#${enumActionEl.DEFAULT_IMAGE_EL}`).on('click', `.${enumActionEl.SET_IMG_EL}`, event => {
  6016 + if ($(event.target).hasClass(enumActionEl.DEL_PREVIEW_IMG)) return
  6017 + generatorUploadLayerComponent((imageState) => {
  6018 + $(`#${enumActionEl.DEFAULT_IMAGE_EL}`)
  6019 + .find('img').attr('src', imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH])
  6020 +
  6021 + form.val(enumActionEl.DEFAULT_IMAGE_FILTER, {
  6022 + [enumConst.IMAGE_ORIGIN]: imageState[enumConst.IMAGE_ORIGIN],
  6023 + [enumConst.IMAGE_GALLERY_CATEGORY]: imageState[enumConst.IMAGE_GALLERY_CATEGORY],
  6024 + [enumConst.IMAGE_GALLERY_IMAGE_PATH]: imageState[enumConst.IMAGE_GALLERY_IMAGE_PATH],
  6025 + })
  6026 +
  6027 + })
  6028 + })
  6029 + }
  6030 +
  6031 + /**
  6032 + * @description 删除默认图片
  6033 + */
  6034 + function createDelDefaultImageEvent() {
  6035 + $(`#${enumActionEl.DEFAULT_IMAGE_EL}`).on('click', `.${enumActionEl.DEL_PREVIEW_IMG}`, (event) => {
  6036 + $(event.target)
  6037 + .parents(`div.${enumActionEl.PREVIEW_IMG_CONTAINER}`).find('img').attr('src', '')
  6038 +
  6039 + form.val(enumActionEl.DEFAULT_IMAGE_FILTER, {
  6040 + [enumConst.IMAGE_ORIGIN]: null,
  6041 + [enumConst.IMAGE_GALLERY_CATEGORY]: null,
  6042 + [enumConst.IMAGE_GALLERY_IMAGE_PATH]: null,
  6043 + })
  6044 +
  6045 + })
6033 6046 }
6034 6047
6035 6048 /**
... ... @@ -6143,25 +6156,12 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6143 6156 </div>
6144 6157 </div>
6145 6158 </td>
6146   -<!-- <td>-->
6147   -<!-- <div style="display: flex">-->
6148   -<!-- <input class="layui-input" style="border-width: 1px; border-right: none;" autocomplete="off" ype="number" name="${enumConst.COLOR}" lay-filter="${enumConst.COLOR}" lay-verType="tips" lay-verify="required" />-->
6149   -<!-- <div id="${getColorPickerFilter(addRowNumber)}"></div>-->
6150   -<!-- </div>-->
6151   -<!-- </td>-->
6152 6159 <td style="text-align: center">
6153 6160 <button type="button" class="layui-btn layui-btn-primary layui-border-red ${enumActionEl.DEL_ROW_EL}">删除</button>
6154 6161 </td>
6155 6162 </tr>
6156 6163 `
6157 6164 $(`#${enumActionEl.TABLE_BODY_EL}`).append(content)
6158   - // colorpicker.render({
6159   - // elem: $(`#${getColorPickerFilter(addRowNumber)}`),
6160   - // done(color) {
6161   - // $(`#${enumActionEl.TABLE_BODY_EL} tr[lay-filter="${rowFormFilter}"]`).find(`input[lay-filter="${enumConst.COLOR}"]`).val(color)
6162   - // },
6163   - // predefine: true,
6164   - // });
6165 6165 form.render()
6166 6166 addRowNumber++
6167 6167 }
... ... @@ -6172,12 +6172,23 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6172 6172 */
6173 6173 function echoFormData(info) {
6174 6174 const { condition = [] } = info
6175   - condition.forEach((item, index) => {
  6175 + for (let index = 0; index < condition.length; index++) {
  6176 + const item = condition[index]
  6177 + if (item[enumConst.DEFAULT_IMAGE_FLAG]) continue
6176 6178 addRecord()
6177 6179 const rowFilter = getRowFilter(index)
6178 6180 $(`#${enumActionEl.TABLE_BODY_EL}`).find(`tr[lay-filter="${rowFilter}"] .${enumActionEl.PREVIEW_IMG_CONTAINER}>img`).attr('src', item[enumConst.IMAGE_GALLERY_IMAGE_PATH])
6179 6181 form.val(rowFilter, { ...item })
6180   - })
  6182 + }
  6183 + }
  6184 +
  6185 + function echoDefaultImage(info) {
  6186 + const { condition } = info
  6187 + const data = condition.find(item => item[enumConst.DEFAULT_IMAGE_FLAG])
  6188 + if (data) {
  6189 + $(`#${enumActionEl.DEFAULT_IMAGE_EL}`).find(`.${enumActionEl.PREVIEW_IMG_CONTAINER}>img`).attr('src', data[enumConst.IMAGE_GALLERY_IMAGE_PATH])
  6190 + form.val(enumActionEl.DEFAULT_IMAGE_FILTER, { ...data })
  6191 + }
6181 6192 }
6182 6193
6183 6194 /**
... ... @@ -6207,6 +6218,9 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6207 6218 */
6208 6219 async function submit(callback) {
6209 6220 const data = Array.from({ length: addRowNumber }).map((_, row) => form.val(getRowFilter(row))).filter(item => Object.keys(item).length)
  6221 + const defaultImageConfig = form.val(enumActionEl.DEFAULT_IMAGE_FILTER)
  6222 + defaultImageConfig[enumConst.DEFAULT_IMAGE_FLAG] = true
  6223 + data.push(defaultImageConfig)
6210 6224 if (!validate(data)) return
6211 6225 const formVal = getDataSourceValue()
6212 6226 const formModel = {
... ... @@ -6226,7 +6240,20 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6226 6240
6227 6241 function createLayerForm(type) {
6228 6242 const content = `
6229   - <div style="width: 300px; padding: 20px 0 0 20px;" id="${enumActionEl.DATA_SOURCE_COMP_EL}"></div>
  6243 + <div id="${enumActionEl.DEFAULT_IMAGE_EL}" class="layui-form" lay-filter="${enumActionEl.DEFAULT_IMAGE_FILTER}">
  6244 + <div style="width: 60px; padding-left: 10px;">默认图片</div>
  6245 + <div class="${enumActionEl.SET_IMG_EL}">
  6246 + <input name="${enumConst.IMAGE_GALLERY_CATEGORY}" type="text" style="display: none">
  6247 + <input name="${enumConst.IMAGE_GALLERY_IMAGE_PATH}" type="text" style="display: none">
  6248 + <input name="${enumConst.IMAGE_ORIGIN}" type="text" style="display: none">
  6249 + <div class="${enumActionEl.PREVIEW_IMG_CONTAINER}">
  6250 + <img src="" alt="">
  6251 + <div class="${enumActionEl.DEL_PREVIEW_IMG}">x</div>
  6252 + <div class="add__button">+</div>
  6253 + </div>
  6254 + </div>
  6255 + </div>
  6256 + <div style="width: 300px; padding: 0 0 0 20px;" id="${enumActionEl.DATA_SOURCE_COMP_EL}"></div>
6230 6257 <div class="override__table" style="padding: 0 20px">
6231 6258 <table class="layui-table" >
6232 6259 <thead>
... ... @@ -6234,7 +6261,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6234 6261 <th style="text-align:center">最小值(>=)</th>
6235 6262 <th style="text-align:center">最大值(<=)</th>
6236 6263 <th style="text-align:center">对应图片</th>
6237   -<!-- <th style="text-align:center">对应的颜色</th>-->
6238 6264 <th style="text-align:center">操作</th>
6239 6265 </tr>
6240 6266 </thead>
... ... @@ -6282,6 +6308,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6282 6308 } else {
6283 6309 echoDataSource(info)
6284 6310 echoFormData(info)
  6311 + echoDefaultImage(info)
6285 6312 }
6286 6313 generatorEventListen()
6287 6314 },
... ... @@ -13465,6 +13492,49 @@ class HandleDynamicEffect {
13465 13492 VIDEO_FLAG: 'videoComponentFlag'
13466 13493 }
13467 13494
  13495 + static enumVarImageConst = {
  13496 +
  13497 + /**
  13498 + * @description 最小值
  13499 + */
  13500 + MIN: 'min',
  13501 +
  13502 + /**
  13503 + * @description 最大值
  13504 + */
  13505 + MAX: 'max',
  13506 +
  13507 + /**
  13508 + * @description 图片字段 key
  13509 + */
  13510 + IMAGE: 'image',
  13511 +
  13512 + /**
  13513 + * @description 颜色
  13514 + */
  13515 + COLOR: 'color',
  13516 +
  13517 + /**
  13518 + * @description 图片来源
  13519 + */
  13520 + IMAGE_ORIGIN: 'imageOrigin',
  13521 +
  13522 + /**
  13523 + * @description 图库图形类别
  13524 + */
  13525 + IMAGE_GALLERY_CATEGORY: 'category',
  13526 +
  13527 + /**
  13528 + * @description 图表图形路径
  13529 + */
  13530 + IMAGE_GALLERY_IMAGE_PATH: 'imagePath',
  13531 +
  13532 + /**
  13533 + * @description 默认图片 flag
  13534 + */
  13535 + DEFAULT_IMAGE_FLAG: 'defaultImageFlag'
  13536 + }
  13537 +
13468 13538 static enumVideoAccessMode = {
13469 13539 MANUAL_ENTER: 0,
13470 13540 STREAMING: 1
... ... @@ -13717,6 +13787,19 @@ class HandleDynamicEffect {
13717 13787 () => {
13718 13788 node.setStyle(`image;image=${imagePath};imageAspect=0;`)
13719 13789 })
  13790 + } else if (!flag && node) {
  13791 + const { condition = [], attr } = this.getBindData(subscriptionId, HandleDynamicEffect.enumActType.IMAGE)
  13792 + const flag = HandleDynamicEffect.enumVarImageConst.DEFAULT_IMAGE_FLAG
  13793 + const defaultBindData = condition.find(item => item[flag])
  13794 + if (defaultBindData) {
  13795 + const { imagePath } = defaultBindData
  13796 + if (!imagePath) return
  13797 + this.insertOnceUpdateFn(
  13798 + node,
  13799 + () => {
  13800 + node.setStyle(`image;image=${imagePath};imageAspect=0;`)
  13801 + })
  13802 + }
13720 13803 }
13721 13804 }
13722 13805
... ...
... ... @@ -440,7 +440,17 @@
440 440 opacity: 0;
441 441 }
442 442
443   -/* ===== 数据动效 */
  443 +#defaultImageEl {
  444 + display: flex;
  445 + align-items: center;
  446 + padding: 20px 0 0 20px;
  447 +}
  448 +
  449 +#defaultImageEl {
  450 +
  451 +}
  452 +
  453 +/* ===== 数据动效 ========= */
444 454 .dynamic-effect__data-source-comp--override {
445 455 padding: 0;
446 456 }
... ...