github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/ui/src/views/data/buildin/excel/List.vue (about)

     1  <template>
     2    <div class="main-table">
     3      <a-table :columns="columns" :data-source="models" :pagination="false" rowKey="id">
     4        <span slot="folderWithPath" slot-scope="text, record">
     5          <a-tooltip placement="top" overlayClassName="tooltip-light">
     6            <template slot="title">
     7              <span>{{record.path | replacePathSep}}</span>
     8            </template>
     9            <a>{{record.path | pathToRelated}}</a>
    10          </a-tooltip>
    11        </span>
    12  
    13        <span slot="action" slot-scope="record">
    14          <a @click="edit(record)" :title="$t('action.edit')"><a-icon type="form" :style="{fontSize: '16px'}" /></a> &nbsp;
    15  
    16          <a-popconfirm
    17              :title="$t('tips.delete')"
    18              :okText="$t('msg.yes')"
    19              :cancelText="$t('msg.no')"
    20              @confirm="remove(record)"
    21          >
    22            <a href="#" :title="$t('action.delete')"><a-icon type="delete" :style="{fontSize: '16px'}" /></a> &nbsp;
    23          </a-popconfirm> &nbsp;
    24  
    25          <a-tooltip placement="top" overlayClassName="tooltip-light">
    26            <template slot="title">
    27              <div class="content-width" style="min-width: 280px;">
    28                <div class="title">{{$t('tips.refer')}}</div>
    29                <div class="content">
    30                  <div>from: {{ record.referName }}</div>
    31                  <div>select: field_name</div>
    32                  <div>where: field_name like '%keywords%'</div>
    33                </div>
    34              </div>
    35            </template>
    36            <a href="#" :title="$t('tips.refer')">&nbsp; <a-icon type="link" :style="{fontSize: '16px'}" /></a>
    37          </a-tooltip>
    38        </span>
    39      </a-table>
    40  
    41      <div class="pagination-wrapper">
    42        <a-pagination @change="onPageChange" :current="page" :total="total" :defaultPageSize="15" simple size="small" />
    43      </div>
    44  
    45      <a-modal
    46        :visible="editModalVisible"
    47        :title="editModalVisible ? editRecord ? `${$t('menu.excel.edit')}: ${editRecord.title}` : $t('title.excel.create') : ''"
    48        :footer="false"
    49        :centered="true"
    50        :width="700"
    51        @cancel="handleCancelEditModal"
    52      >
    53        <Edit
    54          :v-if="editModalVisible"
    55          :id="editModalVisible ? editID ? editID : 0 : null"
    56          :afterSave="handleEditSave"
    57        />
    58      </a-modal>
    59    </div>
    60  </template>
    61  
    62  <script>
    63  
    64  import {listExcel, removeExcel} from "../../../../api/manage";
    65  import {PageSize, pathToRelated, replacePathSep} from "../../../../api/utils";
    66  import debounce from "lodash.debounce"
    67  import Edit from './Edit';
    68  
    69  export default {
    70    name: 'ExcelList',
    71    components: {
    72      Edit,
    73    },
    74    data() {
    75      const columns = [
    76        {
    77          title: this.$i18n.t('form.name'),
    78          dataIndex: 'title',
    79        },
    80        {
    81          title: this.$i18n.t('form.file'),
    82          dataIndex: 'folder',
    83          scopedSlots: { customRender: 'folderWithPath' },
    84          width: 450
    85        },
    86        {
    87          title: this.$i18n.t('form.opt'),
    88          key: 'action',
    89          scopedSlots: { customRender: 'action' },
    90          width: 80
    91        },
    92      ];
    93  
    94      return {
    95        models: [],
    96        columns,
    97  
    98        designVisible: false,
    99        designModel: {},
   100        time: 0,
   101  
   102        page: 1,
   103        total: 0,
   104        pageSize: PageSize,
   105      };
   106    },
   107    computed: {
   108      keywords: function() {
   109        if (this.$route.query && typeof this.$route.query.search === 'string') {
   110          return this.$route.query.search;
   111        }
   112        return '';
   113      },
   114      editID: function() {
   115        if (this.$route.params && this.$route.params.id !== undefined) {
   116          return this.$route.params.id;
   117        }
   118        return null;
   119      },
   120      editModalVisible: function() {
   121        return this.editID !== null;
   122      },
   123      editRecord: function() {
   124        const {editID} = this;
   125        if (!editID) {
   126          return null;
   127        }
   128        return this.models.find(x => x.id == editID);
   129      }
   130    },
   131    watch: {
   132      keywords: function() {
   133        this.onSearch();
   134      }
   135    },
   136    created () {
   137      this.loadData()
   138    },
   139    filters: {
   140      replacePathSep: function (path) {
   141        return replacePathSep(path)
   142      },
   143      pathToRelated: function (path) {
   144        return pathToRelated(path)
   145      }
   146    },
   147    methods: {
   148      create() {
   149        this.$router.push({path: '/data/buildin/excel/edit/0'});
   150      },
   151      loadData() {
   152        listExcel(this.keywords, this.page).then(json => {
   153          console.log('listExcel', json)
   154          this.models = json.data
   155          this.total = json.total
   156        })
   157      },
   158      handleCancelEditModal() {
   159        const {path, query} = this.$route;
   160        const newPath = '/data/buildin/excel/list';
   161        if (path !== newPath) {
   162          this.$router.replace({path: newPath, query});
   163        }
   164      },
   165      handleEditSave() {
   166        this.handleCancelEditModal();
   167        this.loadData();
   168      },
   169      edit(record) {
   170        const {path, query = {}} = this.$router;
   171        const newPath = `/data/buildin/excel/list/${record.id}`;
   172        if (path !== newPath) {
   173          this.$router.replace({path: newPath, query});
   174        }
   175      },
   176      remove(record) {
   177        console.log(record)
   178        removeExcel(record.id).then(json => {
   179          console.log('removeExcel', json)
   180          this.loadData()
   181        })
   182      },
   183  
   184      handleDesignOk() {
   185        console.log('handleDesignOk')
   186        this.designVisible = false
   187      },
   188      handleDesignCancel() {
   189        console.log('handleDesignCancel')
   190        this.designVisible = false
   191      },
   192  
   193      onPageChange(page, pageSize) {
   194        console.log('onPageChange', page, pageSize)
   195        this.page= page
   196        this.loadData()
   197      },
   198      onSearch: debounce(function() {
   199        console.log('onSearch', this.keywords)
   200        this.loadData()
   201      }, 500),
   202    }
   203  }
   204  </script>
   205  
   206  <style scoped>
   207  
   208  </style>