github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/ui/src/views/data/buildin/text/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>range: {{ record.referName }}</div>
    31                </div>
    32              </div>
    33            </template>
    34            <a href="#" :title="$t('tips.refer')">&nbsp; <a-icon type="link" :style="{fontSize: '16px'}" /></a>
    35          </a-tooltip>
    36  
    37        </span>
    38  
    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.text.edit')}: ${editRecord.title}` : $t('title.text.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 {listText, removeText} 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: 'TextList',
    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    mounted () {
   140    },
   141    filters: {
   142      replacePathSep: function (path) {
   143        return replacePathSep(path)
   144      },
   145      pathToRelated: function (path) {
   146        return pathToRelated(path)
   147      }
   148    },
   149    methods: {
   150      create() {
   151        this.$router.push({path: '/data/buildin/text/edit/0'});
   152      },
   153      loadData() {
   154        listText(this.keywords, this.page).then(json => {
   155          console.log('listText', json)
   156          this.models = json.data
   157          this.total = json.total
   158        })
   159      },
   160      handleCancelEditModal() {
   161        const {path, query} = this.$route;
   162        const newPath = '/data/buildin/text/list';
   163        if (path !== newPath) {
   164          this.$router.replace({path: newPath, query});
   165        }
   166      },
   167      handleEditSave() {
   168        this.handleCancelEditModal();
   169        this.loadData();
   170      },
   171      edit(record) {
   172        const {path, query = {}} = this.$router;
   173        const newPath = `/data/buildin/text/list/${record.id}`;
   174        if (path !== newPath) {
   175          this.$router.replace({path: newPath, query});
   176        }
   177      },
   178      remove(record) {
   179        console.log(record)
   180        removeText(record.id).then(json => {
   181          console.log('removeText', json)
   182          this.loadData()
   183        })
   184      },
   185  
   186      handleDesignOk() {
   187        console.log('handleDesignOk')
   188        this.designVisible = false
   189      },
   190      handleDesignCancel() {
   191        console.log('handleDesignCancel')
   192        this.designVisible = false
   193      },
   194  
   195      onPageChange(page, pageSize) {
   196        console.log('onPageChange', page, pageSize)
   197        this.page= page
   198        this.loadData()
   199      },
   200      onSearch: debounce(function() {
   201        console.log('onSearch', this.keywords)
   202        this.loadData()
   203      }, 500),
   204    }
   205  }
   206  </script>
   207  
   208  <style scoped>
   209  
   210  </style>