entityManager.vue.ftl 3.21 KB
<#assign baseUrl><#noparse>${</#noparse>${cfg.system}<#noparse>}</#noparse><#if package.ModuleName??>/${package.ModuleName}</#if>/${table.entityPath}/v1</#assign>
<template>
  <div>
    <ht-table
      ref="htTable"
      :data="rows"
      :pageResult="pagination"
      :selection="true"
      quick-search-props="${table.fields[0].propertyName}"
      :show-export="false"
      :show-custom-column="false"
      @loading="loadData"
    >
      <template v-slot:toolbar>
        <el-button-group>
          <el-button size="small" @click="showDialog()" icon="el-icon-plus">添加</el-button>
          <el-button
            v-popconfirm="{ before: removeValid, confirm: handleRemove }"
            type="danger"
            icon="el-icon-delete"
          >删除</el-button>
        </el-button-group>
      </template>
      <template>
        <ht-table-column type="index" width="50" align="center" label="序号" />
        <#list table.fields as field>
        <#assign propertyName>${cfg.cgUtil.getPropertyName(cfg.boEntList,table.name,field.name,field.propertyName)}</#assign>
        <ht-table-column
          prop="${propertyName}"
          label="${field.comment!""}"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
          <#if field_index == 0  >
          <template v-slot="{row}">
            <el-link
              type="primary"
              @click="showDialog(row.id)"
              title="查看详情"
            >{{row.${propertyName}}}</el-link>
          </template>
          </#if>
        </ht-table-column>
        </#list>
      </template>
    </ht-table>
    <${table.entityName}-manager-edit ref="${table.entityName}ManagerEdit"></${table.entityName}-manager-edit>
  </div>
</template>
<script>
import ${table.entityName}ManagerEdit from "./${table.entityName}ManagerEdit.vue";
import api from "@/api/${table.entityName}.js"
export default {
  name: '${table.entityName}Manager', 
  components:{${table.entityName}ManagerEdit},
  data() {
    return {
      dialogVisible: false,
      rows: [],
      pagination: {
        page: 1,
        pageSize: 50,
        total: 0
      },
      ${table.entityName}: {},
      saveMethod: "POST"
    };
  },
  computed: {
	tableHeight() {
	  return this.$baseTableHeight()
	},
  },
  methods: {
    showDialog(id) {
      this.$refs.${table.entityName}ManagerEdit.showDialog(id);
    },
    loadData(param, cb) {
      api.loadData(param||{}).then(
        (resp) => {
          let response = resp.data || resp
          this.rows = response.rows
          this.total = response.total
          this.pagination = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        }
      )
      .finally(() => cb && cb());
    },
    removeValid() {
        if (this.$refs.htTable.selection.length == 0) {
          this.$message({ message: '请至少选择一条记录', type: 'warning' })
          return false
        }
        return true
      },
      handleRemove() {
        const ids = []
        this.$refs.htTable.selection.forEach((item) => {
          ids.push(item.id)
        })
        api.deleteByIds(ids.join(',')).then(() => {
          this.loadData()
        })
      },
  }
};
</script>