TableList.vue 8.6 KB

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