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