github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/ui/src/views/data/buildin/instances/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> 15 <a @click="design(record)" :title="$t('action.design')"><a-icon type="control" :style="{fontSize: '16px'}" /></a> 16 17 <a-popconfirm 18 :title="$t('tips.delete')" 19 :okText="$t('msg.yes')" 20 :cancelText="$t('msg.no')" 21 @confirm="remove(record)" 22 > 23 <a href="#" :title="$t('action.delete')"><a-icon type="delete" :style="{fontSize: '16px'}" /></a> 24 </a-popconfirm> 25 26 <a-tooltip placement="top" overlayClassName="tooltip-light"> 27 <template slot="title"> 28 <div class="content-width" style="min-width: 280px;"> 29 <div class="title">{{$t('tips.refer')}}</div> 30 <div class="content"> 31 <div>from: {{ record.referName }}</div> 32 <div>use: field_name</div> 33 </div> 34 </div> 35 </template> 36 <a href="#" :title="$t('tips.refer')"> <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 <div class="full-screen-modal"> 46 <design-component 47 ref="designPage" 48 :type="type" 49 :visible="designVisible" 50 :modelProp="designModel" 51 :time="time" 52 @ok="handleDesignOk" 53 @cancel="handleDesignCancel" > 54 </design-component> 55 </div> 56 57 <a-modal 58 :visible="editModalVisible" 59 :title="editModalVisible ? editRecord ? `${$t('menu.instances.edit')}: ${editRecord.title}` : $t('title.instances.create') : ''" 60 :footer="false" 61 :centered="true" 62 :width="700" 63 @cancel="handleCancelEditModal" 64 > 65 <Edit 66 :v-if="editModalVisible" 67 :id="editModalVisible ? editID ? editID : 0 : null" 68 :afterSave="handleEditSave" 69 /> 70 </a-modal> 71 </div> 72 </template> 73 74 <script> 75 76 import {listInstances, removeInstances} from "../../../../api/manage"; 77 import { DesignComponent } from '../../../../components' 78 import {PageSize, ResTypeInstances, pathToRelated, replacePathSep} from "../../../../api/utils"; 79 import debounce from "lodash.debounce" 80 import Edit from './Edit'; 81 82 export default { 83 name: 'InstanceList', 84 components: { 85 DesignComponent, 86 Edit, 87 }, 88 data() { 89 const columns = [ 90 { 91 title: this.$i18n.t('form.name'), 92 dataIndex: 'title', 93 }, 94 { 95 title: this.$i18n.t('form.file'), 96 dataIndex: 'folder', 97 scopedSlots: { customRender: 'folderWithPath' }, 98 width: 450 99 }, 100 { 101 title: this.$i18n.t('form.opt'), 102 key: 'action', 103 scopedSlots: { customRender: 'action' }, 104 width: 100 105 }, 106 ]; 107 108 return { 109 models: [], 110 columns, 111 112 designVisible: false, 113 designModel: {}, 114 type: ResTypeInstances, 115 time: 0, 116 117 page: 1, 118 total: 0, 119 pageSize: PageSize, 120 }; 121 }, 122 computed: { 123 keywords: function() { 124 if (this.$route.query && typeof this.$route.query.search === 'string') { 125 return this.$route.query.search; 126 } 127 return ''; 128 }, 129 editID: function() { 130 if (this.$route.params && this.$route.params.id !== undefined) { 131 return this.$route.params.id; 132 } 133 return null; 134 }, 135 editModalVisible: function() { 136 return this.editID !== null; 137 }, 138 editRecord: function() { 139 const {editID} = this; 140 if (!editID) { 141 return null; 142 } 143 return this.models.find(x => x.id == editID); 144 } 145 }, 146 watch: { 147 keywords: function() { 148 this.onSearch(); 149 } 150 }, 151 created () { 152 this.loadData() 153 }, 154 mounted () { 155 }, 156 filters: { 157 replacePathSep: function (path) { 158 return replacePathSep(path) 159 }, 160 pathToRelated: function (path) { 161 return pathToRelated(path) 162 } 163 }, 164 methods: { 165 create() { 166 this.$router.push({path: '/data/buildin/instances/edit/0'}); 167 }, 168 loadData() { 169 listInstances(this.keywords, this.page).then(json => { 170 console.log('listInstances', json) 171 this.models = json.data 172 this.total = json.total 173 }) 174 }, 175 handleCancelEditModal() { 176 const {path, query} = this.$route; 177 const newPath = '/data/buildin/instances/list'; 178 if (path !== newPath) { 179 this.$router.replace({path: newPath, query}); 180 } 181 }, 182 handleEditSave() { 183 this.handleCancelEditModal(); 184 this.loadData(); 185 }, 186 edit(record) { 187 const {path, query = {}} = this.$router; 188 const newPath = `/data/buildin/instances/list/${record.id}`; 189 if (path !== newPath) { 190 this.$router.replace({path: newPath, query}); 191 } 192 }, 193 design(record) { 194 this.time = Date.now() // trigger data refresh 195 console.log(record) 196 this.designVisible = true 197 this.designModel = record 198 }, 199 remove(record) { 200 console.log(record) 201 removeInstances(record.id).then(json => { 202 console.log('removeInstances', json) 203 this.loadData() 204 }) 205 }, 206 207 handleDesignOk() { 208 console.log('handleDesignOk') 209 this.designVisible = false 210 }, 211 handleDesignCancel() { 212 console.log('handleDesignCancel') 213 this.designVisible = false 214 }, 215 216 onPageChange(page, pageSize) { 217 console.log('onPageChange', page, pageSize) 218 this.page= page 219 this.loadData() 220 }, 221 onSearch: debounce(function() { 222 console.log('onSearch', this.keywords) 223 this.loadData() 224 }, 500), 225 } 226 } 227 </script> 228 229 <style scoped> 230 231 </style>