ddb0a26e9c09adeed5b72d14a2be9eefbc661c3f.svn-base 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 placeholder=""/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8" :sm="24">
  12. <a-form-item label="使用状态">
  13. <a-select 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 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 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 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">查询</a-button>
  53. <a-button style="margin-left: 8px">重置</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="() => this.handleModalVisible(true)">新建</a-button>
  65. <a-dropdown v-if="selectedRowKeys.length > 0">
  66. <a-menu slot="overlay">
  67. <a-menu-item key="1"><a-icon type="delete" />删除</a-menu-item>
  68. <!-- lock | unlock -->
  69. <a-menu-item key="2"><a-icon type="lock" />锁定</a-menu-item>
  70. </a-menu>
  71. <a-button style="margin-left: 8px">
  72. 批量操作 <a-icon type="down" />
  73. </a-button>
  74. </a-dropdown>
  75. </div>
  76. <s-table
  77. ref="table"
  78. size="default"
  79. :columns="columns"
  80. :data="loadData"
  81. :showAlertInfo="true"
  82. @onSelect="onChange"
  83. >
  84. <template v-for="(col, index) in columns" v-if="col.scopedSlots" :slot="col.dataIndex" slot-scope="text, record, index">
  85. <div :key="index">
  86. <a-input
  87. v-if="record.editable"
  88. style="margin: -5px 0"
  89. :value="text"
  90. @change="e => handleChange(e.target.value, record.key, col)"
  91. />
  92. <template v-else>{{ text }}</template>
  93. </div>
  94. </template>
  95. <template slot="action" slot-scope="text, record, index">
  96. <div class="editable-row-operations">
  97. <span v-if="record.editable">
  98. <a @click="() => save(record)">保存</a>
  99. <a-divider type="vertical" />
  100. <a-popconfirm title="真的放弃编辑吗?" @confirm="() => cancel(record)">
  101. <a>取消</a>
  102. </a-popconfirm>
  103. </span>
  104. <span v-else>
  105. <a class="edit" @click="() => edit(record)">修改</a>
  106. <a-divider type="vertical" />
  107. <a class="delete" @click="() => del(record)">删除</a>
  108. </span>
  109. </div>
  110. </template>
  111. </s-table>
  112. <a-modal title="新建规则" destroyOnClose :visible="visibleCreateModal" @ok="handleCreateModalOk" @cancel="handleCreateModalCancel">
  113. <!---->
  114. <a-form style="margin-top: 8px" :autoFormCreate="(form)=>{this.createForm = form}">
  115. <a-form-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="描述" fieldDecoratorId="description" :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 }]}">
  116. <a-input placeholder="请输入" />
  117. </a-form-item>
  118. </a-form>
  119. </a-modal>
  120. </a-card>
  121. </template>
  122. <script>
  123. import STable from '@/components/table/'
  124. export default {
  125. name: "TableList",
  126. components: {
  127. STable
  128. },
  129. data () {
  130. return {
  131. // 高级搜索 展开/关闭
  132. advanced: false,
  133. // 查询参数
  134. queryParam: {},
  135. // 表头
  136. columns: [
  137. {
  138. title: '规则编号',
  139. dataIndex: 'no',
  140. width: 90
  141. },
  142. {
  143. title: '描述',
  144. dataIndex: 'description',
  145. scopedSlots: { customRender: 'description' },
  146. },
  147. {
  148. title: '服务调用次数',
  149. dataIndex: 'callNo',
  150. width: '150px',
  151. sorter: true,
  152. needTotal: true,
  153. scopedSlots: { customRender: 'callNo' },
  154. // customRender: (text) => text + ' 次'
  155. },
  156. {
  157. title: '状态',
  158. dataIndex: 'status',
  159. width: '100px',
  160. needTotal: true,
  161. scopedSlots: { customRender: 'status' },
  162. },
  163. {
  164. title: '更新时间',
  165. dataIndex: 'updatedAt',
  166. width: '150px',
  167. sorter: true,
  168. scopedSlots: { customRender: 'updatedAt' },
  169. },
  170. {
  171. table: '操作',
  172. dataIndex: 'action',
  173. width: '120px',
  174. scopedSlots: { customRender: 'action' },
  175. }
  176. ],
  177. // 加载数据方法 必须为 Promise 对象
  178. loadData: parameter => {
  179. return this.$http.get('/mock/api/service', {
  180. params: Object.assign(parameter, this.queryParam)
  181. }).then(res => {
  182. return res.result
  183. })
  184. },
  185. selectedRowKeys: [],
  186. selectedRows: [],
  187. visibleCreateModal:false
  188. }
  189. },
  190. methods: {
  191. handleChange (value, key, column) {
  192. console.log(value, key, column)
  193. },
  194. edit (row) {
  195. row.editable = true
  196. // row = Object.assign({}, row)
  197. this.$refs.table.updateEdit()
  198. },
  199. // eslint-disable-next-line
  200. del (row) {
  201. this.$confirm({
  202. title: '警告',
  203. content: '真的要删除吗?',
  204. okText: '删除',
  205. okType: 'danger',
  206. cancelText: '取消',
  207. onOk() {
  208. console.log('OK');
  209. // 在这里调用删除接口
  210. return new Promise((resolve, reject) => {
  211. setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
  212. }).catch(() => console.log('Oops errors!'));
  213. },
  214. onCancel() {
  215. console.log('Cancel');
  216. },
  217. });
  218. },
  219. save (row) {
  220. delete row.editable
  221. this.$refs.table.updateEdit()
  222. },
  223. cancel (row) {
  224. delete row.editable
  225. this.$refs.table.updateEdit()
  226. },
  227. onChange (row) {
  228. this.selectedRowKeys = row.selectedRowKeys
  229. this.selectedRows = row.selectedRows
  230. },
  231. toggleAdvanced () {
  232. this.advanced = !this.advanced
  233. },
  234. //添加逻辑
  235. handleModalVisible(isVisible) {
  236. this.visibleCreateModal = isVisible;
  237. },
  238. handleCreateModalCancel() {
  239. this.visibleCreateModal = false;
  240. },
  241. handleCreateModalOk() {
  242. this.visibleCreateModal = false;
  243. },
  244. },
  245. watch: {
  246. /*
  247. 'selectedRows': function (selectedRows) {
  248. this.needTotalList = this.needTotalList.map(item => {
  249. return {
  250. ...item,
  251. total: selectedRows.reduce( (sum, val) => {
  252. return sum + val[item.dataIndex]
  253. }, 0)
  254. }
  255. })
  256. }
  257. */
  258. }
  259. }
  260. </script>
  261. <style lang="less" scoped>
  262. .search {
  263. margin-bottom: 54px;
  264. }
  265. .fold {
  266. width: calc(100% - 216px);
  267. display: inline-block
  268. }
  269. .operator {
  270. margin-bottom: 18px;
  271. }
  272. @media screen and (max-width: 900px) {
  273. .fold {
  274. width: 100%;
  275. }
  276. }
  277. </style>