opentiny / tiny-vue

TinyVue is an enterprise-class UI component library of OpenTiny community, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
https://opentiny.design/tiny-vue
MIT License
1.66k stars 264 forks source link

🐛 [Bug]: Grid-column默认插槽中读取深层次字段时控制台会有警告 #1279

Closed ichynul closed 3 months ago

ichynul commented 10 months ago

Version

3.12

Vue Version

3.3

Link to minimal reproduction

https://opentiny.design/vue-playground?mode=pc&theme=default#3.12|eyJzcmMvQXBwLnZ1ZSI6IjxzY3JpcHQgbGFuZz1cInRzeFwiPlxyXG4vLyDlvJXlhaUgQG9wZW50aW55L3Z1ZSDnu4Tku7ZcclxuaW1wb3J0IHsgQnV0dG9uLCBMaW5rIH0gZnJvbSAnQG9wZW50aW55L3Z1ZSdcclxuXHJcbmV4cG9ydCBkZWZhdWx0IHtcclxuICBjb21wb25lbnRzOiB7XHJcbiAgICBUaW55QnV0dG9uOiBCdXR0b24sXHJcbiAgICBUaW55TGluazogTGlua1xyXG4gIH0sXHJcbiAgZGF0YSgpIHtcclxuICAgIHJldHVybiB7XHJcbiAgICAgIG1zZzogJ2hlbGxvIHdvcmxkISdcclxuICAgIH1cclxuICB9XHJcbn1cclxuPC9zY3JpcHQ+XHJcblxyXG48dGVtcGxhdGU+XHJcbiAgPFRpbnlCdXR0b24+56Gu5a6aPC9UaW55QnV0dG9uPlxyXG4gIDxoMT57eyBtc2cgfX08L2gxPlxyXG4gIDxkaXYgY2xhc3M9XCJ0aW55dnVlXCI+XHJcbiAgICA8ZGl2IGNsYXNzPVwidGlueXZ1ZS1wYWdlXCI+XHJcbiAgICAgIHRpbnl2dWVcclxuICAgICAgPHRpbnktbGluayB0eXBlPVwic3VjY2Vzc1wiIGhyZWY9J2h0dHBzOi8vZ2l0aHViLmNvbS9vcGVudGlueS90aW55LXZ1ZSc+XHJcbiAgICAgICAgdGlueXZ1ZVxyXG4gICAgICA8L3RpbnktbGluaz5cclxuICAgIDwvZGl2PlxyXG4gIDwvZGl2PlxyXG48L3R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AuZGVtby1jdXN0b20tY29sdW1uIHN2Zzpub3QoOmxhc3QtY2hpbGQpIHtcbiAgICBtYXJnaW4tcmlnaHQ6IDhweDtcbiAgfVxuPC9zdHlsZT4iLCJfbyI6e319

Step to reproduce

<template>
  <tiny-grid :data="tableData">
    <tiny-grid-column type="index" width="60"></tiny-grid-column>
    <tiny-grid-column type="selection" width="60"></tiny-grid-column>
    <tiny-grid-column field="name" title="名称"></tiny-grid-column>
    <tiny-grid-column field="area" title="所属区域"></tiny-grid-column>
    <tiny-grid-column field="address" title="地址"></tiny-grid-column>
    <tiny-grid-column field="introduction" title="公司简介" show-overflow></tiny-grid-column>
    <tiny-grid-column title="操作" width="100">
      <template #default="data">
        <div class="demo-custom-column"><!-- 在此元素加上 v-if="data.row.__action__" 可解决 -->
          <tiny-button :disabled="data.row.__action__.search.disabled">
            <tiny-icon-search class="tiny-svg-size" @click="clickHandler(data.row)"></tiny-icon-search>
            {{data.row.__action__.search.label}}
          </tiny-button>
          <tiny-button :disabled="data.row.__action__.edit.disabled">
            <tiny-icon-edit class="tiny-svg-size" @click="clickHandler(data.row)"></tiny-icon-edit>
            {{data.row.__action__.edit.label}}
            <!--插槽中只能使用 data.row.xxx -->
            <!--
              层级更深如 data.row.xxx.yyy、data.row.xxx.yyy.zzz
              在数据源为空时(如首次异步加载数据期间)
              控制台会警告:[tiny-grid] 列的默认插槽中存在语法错误,请检查。
            -->
          </tiny-button>
        </div>
      </template>
    </tiny-grid-column>
  </tiny-grid>
</template>

<script setup lang="jsx">
  import { ref } from 'vue'
  import { Grid as TinyGrid, Button as TinyButton, GridColumn as TinyGridColumn, Modal } from '@opentiny/vue'
  import { iconEdit, iconSearch } from '@opentiny/vue-icon'

  let data = [
    {
      id: '1',
      name: 'GFD科技YX公司',
      area: '华东区',
      address: '福州',
      introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。',
      __action__: {
        search: { label: '搜索', disabled: false },
        edit: { label: '编辑', disabled: true }
      }
    },
    {
      id: '2',
      name: 'WWWW科技YX公司',
      area: '华南区',
      address: '深圳福田区',
      introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。',
      __action__: {
        search: { label: '搜索', disabled: false },
        edit: { label: '编辑', disabled: false }
      }
    },
    {
      id: '3',
      name: 'RFV有限责任公司',
      area: '华南区',
      address: '中山市',
      introduction: '公司技术和研发实力雄厚,是国家863项目的参与者,并被政府认定为“高新技术企业”。',
      __action__: {
        search: { label: '搜索', disabled: true },
        edit: { label: '编辑', disabled: false }
      }
    },
  ];

  // const tableData = ref(data); //直接绑定,正常

  //模拟数据请求延迟
  const tableData = ref([]);
  setTimeout(() => {
    tableData.value = data;
  }, 500);

  const TinyIconEdit = iconEdit()
  const TinyIconSearch = iconSearch()

  function clickHandler(row) {
    Modal.message({ message: JSON.stringify(row), status: 'success' })
  }
</script>

<style scoped>
  .demo-custom-column {
    font-size: 0;
  }

  .demo-custom-column svg {
    font-size: 16px;
    fill: var(--ti-common-color-line-active);
  }

  .demo-custom-column svg:hover {
    fill: #40a9ff;
    cursor: pointer;
  }

  .demo-custom-column svg:not(:last-child) {
    margin-right: 8px;
  }
</style>

What is expected

层级只能读到data.row的下一级

<tiny-grid-column title="操作" width="100">
<template #default="data">
{{data.row.aaa}}
</template>
</tiny-grid-column>

What is actually happening

{{data.row.xxx.yyy}} 层级过深的情况下。 表格数据空时,控制台会警告:[tiny-grid] 列的默认插槽中存在语法错误,请检查。 界面没什么异常,就是提示让人觉得是有什么地方有问题。

Any additional comments (optional)

No response

Issues-translate-bot commented 10 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: 🐛 [Bug]: There will be a warning on the console when reading deep fields in the default slot of Grid-column