TableList.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline">
  5. <a-row :gutter="48">
  6. <a-col :md="8" :sm="24">
  7. <a-form-item label="规则编号">
  8. <a-input v-model="queryParam.id" placeholder=""/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8" :sm="24">
  12. <a-form-item label="使用状态">
  13. <a-select v-model="queryParam.status" placeholder="请选择" default-value="0">
  14. <a-select-option value="0">全部</a-select-option>
  15. <a-select-option value="1">关闭</a-select-option>
  16. <a-select-option value="2">运行中</a-select-option>
  17. </a-select>
  18. </a-form-item>
  19. </a-col>
  20. <template v-if="advanced">
  21. <a-col :md="8" :sm="24">
  22. <a-form-item label="调用次数">
  23. <a-input-number v-model="queryParam.callNo" style="width: 100%"/>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="8" :sm="24">
  27. <a-form-item label="更新日期">
  28. <a-date-picker v-model="queryParam.date" style="width: 100%" placeholder="请输入更新日期"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :md="8" :sm="24">
  32. <a-form-item label="使用状态">
  33. <a-select v-model="queryParam.useStatus" placeholder="请选择" default-value="0">
  34. <a-select-option value="0">全部</a-select-option>
  35. <a-select-option value="1">关闭</a-select-option>
  36. <a-select-option value="2">运行中</a-select-option>
  37. </a-select>
  38. </a-form-item>
  39. </a-col>
  40. <a-col :md="8" :sm="24">
  41. <a-form-item label="使用状态">
  42. <a-select placeholder="请选择" default-value="0">
  43. <a-select-option value="0">全部</a-select-option>
  44. <a-select-option value="1">关闭</a-select-option>
  45. <a-select-option value="2">运行中</a-select-option>
  46. </a-select>
  47. </a-form-item>
  48. </a-col>
  49. </template>
  50. <a-col :md="!advanced && 8 || 24" :sm="24">
  51. <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
  52. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  53. <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
  54. <a @click="toggleAdvanced" style="margin-left: 8px">
  55. {{ advanced ? '收起' : '展开' }}
  56. <a-icon :type="advanced ? 'up' : 'down'"/>
  57. </a>
  58. </span>
  59. </a-col>
  60. </a-row>
  61. </a-form>
  62. </div>
  63. <div class="table-operator">
  64. <a-button type="primary" icon="plus" @click="$refs.createModal.add()">新建</a-button>
  65. <a-button type="dashed" @click="tableOption">{{ optionAlertShow && '关闭' || '开启' }} alert</a-button>
  66. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0">
  67. <a-menu slot="overlay">
  68. <a-menu-item key="1"><a-icon type="delete" />删除</a-menu-item>
  69. <!-- lock | unlock -->
  70. <a-menu-item key="2"><a-icon type="lock" />锁定</a-menu-item>
  71. </a-menu>
  72. <a-button style="margin-left: 8px">
  73. 批量操作 <a-icon type="down" />
  74. </a-button>
  75. </a-dropdown>
  76. </div>
  77. <s-table
  78. ref="table"
  79. size="default"
  80. rowKey="key"
  81. :columns="columns"
  82. :data="loadData"
  83. :alert="options.alert"
  84. :rowSelection="options.rowSelection"
  85. showPagination="auto"
  86. >
  87. <span slot="serial" slot-scope="text, record, MenuIndex">
  88. {{ MenuIndex + 1 }}
  89. </span>
  90. <span slot="status" slot-scope="text">
  91. <a-badge :status="text | statusTypeFilter" :text="text | statusFilter" />
  92. </span>
  93. <span slot="description" slot-scope="text">
  94. <ellipsis :length="4" tooltip>{{ text }}</ellipsis>
  95. </span>
  96. <span slot="action" slot-scope="text, record">
  97. <template>
  98. <a @click="handleEdit(record)">配置</a>
  99. <a-divider type="vertical" />
  100. <a @click="handleSub(record)">订阅报警</a>
  101. </template>
  102. </span>
  103. </s-table>
  104. <create-form ref="createModal" @ok="handleOk" />
  105. <step-by-step-modal ref="modal" @ok="handleOk"/>
  106. </a-card>
  107. </template>
  108. <script>
  109. import moment from 'moment'
  110. import { STable, Ellipsis } from '@/components'
  111. import StepByStepModal from './modules/StepByStepModal'
  112. import CreateForm from './modules/CreateForm'
  113. import { getRoleList, getServiceList } from '@/api/manage'
  114. const statusMap = {
  115. 0: {
  116. status: 'default',
  117. text: '关闭'
  118. },
  119. 1: {
  120. status: 'processing',
  121. text: '运行中'
  122. },
  123. 2: {
  124. status: 'success',
  125. text: '已上线'
  126. },
  127. 3: {
  128. status: 'error',
  129. text: '异常'
  130. }
  131. }
  132. export default {
  133. name: 'TableList',
  134. components: {
  135. STable,
  136. Ellipsis,
  137. CreateForm,
  138. StepByStepModal
  139. },
  140. data () {
  141. return {
  142. mdl: {},
  143. // 高级搜索 展开/关闭
  144. advanced: false,
  145. // 查询参数
  146. queryParam: {},
  147. // 表头
  148. columns: [
  149. {
  150. title: '#',
  151. scopedSlots: { customRender: 'serial' }
  152. },
  153. {
  154. title: '规则编号',
  155. dataIndex: 'no'
  156. },
  157. {
  158. title: '描述',
  159. dataIndex: 'description',
  160. scopedSlots: { customRender: 'description' }
  161. },
  162. {
  163. title: '服务调用次数',
  164. dataIndex: 'callNo',
  165. sorter: true,
  166. needTotal: true,
  167. customRender: (text) => text + ' 次'
  168. },
  169. {
  170. title: '状态',
  171. dataIndex: 'status',
  172. scopedSlots: { customRender: 'status' }
  173. },
  174. {
  175. title: '更新时间',
  176. dataIndex: 'updatedAt',
  177. sorter: true
  178. },
  179. {
  180. title: '操作',
  181. dataIndex: 'action',
  182. width: '150px',
  183. scopedSlots: { customRender: 'action' }
  184. }
  185. ],
  186. // 加载数据方法 必须为 Promise 对象
  187. loadData: parameter => {
  188. console.log('loadData.parameter', parameter)
  189. return getServiceList(Object.assign(parameter, this.queryParam))
  190. .then(res => {
  191. return res.result
  192. })
  193. },
  194. selectedRowKeys: [],
  195. selectedRows: [],
  196. // custom table alert & rowSelection
  197. options: {
  198. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  199. rowSelection: {
  200. selectedRowKeys: this.selectedRowKeys,
  201. onChange: this.onSelectChange
  202. }
  203. },
  204. optionAlertShow: false
  205. }
  206. },
  207. filters: {
  208. statusFilter (type) {
  209. return statusMap[type].text
  210. },
  211. statusTypeFilter (type) {
  212. return statusMap[type].status
  213. }
  214. },
  215. created () {
  216. this.tableOption()
  217. getRoleList({ t: new Date() })
  218. },
  219. methods: {
  220. tableOption () {
  221. if (!this.optionAlertShow) {
  222. this.options = {
  223. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  224. rowSelection: {
  225. selectedRowKeys: this.selectedRowKeys,
  226. onChange: this.onSelectChange,
  227. getCheckboxProps: record => ({
  228. props: {
  229. disabled: record.no === 'No 2', // Column configuration not to be checked
  230. name: record.no
  231. }
  232. })
  233. }
  234. }
  235. this.optionAlertShow = true
  236. } else {
  237. this.options = {
  238. alert: false,
  239. rowSelection: null
  240. }
  241. this.optionAlertShow = false
  242. }
  243. },
  244. handleEdit (record) {
  245. console.log(record)
  246. this.$refs.modal.edit(record)
  247. },
  248. handleSub (record) {
  249. if (record.status !== 0) {
  250. this.$message.info(`${record.no} 订阅成功`)
  251. } else {
  252. this.$message.error(`${record.no} 订阅失败,规则已关闭`)
  253. }
  254. },
  255. handleOk () {
  256. this.$refs.table.refresh()
  257. },
  258. onSelectChange (selectedRowKeys, selectedRows) {
  259. this.selectedRowKeys = selectedRowKeys
  260. this.selectedRows = selectedRows
  261. },
  262. toggleAdvanced () {
  263. this.advanced = !this.advanced
  264. },
  265. resetSearchForm () {
  266. this.queryParam = {
  267. date: moment(new Date())
  268. }
  269. }
  270. }
  271. }
  272. </script>