TableInnerEditList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <a-card :bordered="false">
  3. <div :class="advanced ? 'search' : null">
  4. <a-form layout="horizontal">
  5. <div :class="advanced ? null : 'fold'">
  6. <a-row :gutter="48">
  7. <a-col :md="8" :sm="24">
  8. <a-form-item
  9. label="规则编号"
  10. :labelCol="{span: 5}"
  11. :wrapperCol="{span: 18, offset: 1}"
  12. >
  13. <a-input placeholder="请输入"/>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="8" :sm="24">
  17. <a-form-item
  18. label="使用状态"
  19. :labelCol="{span: 5}"
  20. :wrapperCol="{span: 18, offset: 1}"
  21. >
  22. <a-select placeholder="请选择">
  23. <a-select-option value="1">关闭</a-select-option>
  24. <a-select-option value="2">运行中</a-select-option>
  25. </a-select>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="8" :sm="24">
  29. <a-form-item
  30. label="调用次数"
  31. :labelCol="{span: 5}"
  32. :wrapperCol="{span: 18, offset: 1}"
  33. >
  34. <a-input-number style="width: 100%" placeholder="请输入"/>
  35. </a-form-item>
  36. </a-col>
  37. </a-row>
  38. <a-row :gutter="48" v-if="advanced">
  39. <a-col :md="8" :sm="24">
  40. <a-form-item
  41. label="更新日期"
  42. :labelCol="{span: 5}"
  43. :wrapperCol="{span: 18, offset: 1}">
  44. <a-date-picker style="width: 100%" placeholder="请输入更新日期"/>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :md="8" :sm="24">
  48. <a-form-item
  49. label="使用状态"
  50. :labelCol="{span: 5}"
  51. :wrapperCol="{span: 18, offset: 1}">
  52. <a-select placeholder="请选择">
  53. <a-select-option value="1">关闭</a-select-option>
  54. <a-select-option value="2">运行中</a-select-option>
  55. </a-select>
  56. </a-form-item>
  57. </a-col>
  58. <a-col :md="8" :sm="24">
  59. <a-form-item
  60. label="描述"
  61. :labelCol="{span: 5}"
  62. :wrapperCol="{span: 18, offset: 1}"
  63. >
  64. <a-input placeholder="请输入"/>
  65. </a-form-item>
  66. </a-col>
  67. </a-row>
  68. </div>
  69. <span style="float: right; margin-top: 3px;">
  70. <a-button type="primary">查询</a-button>
  71. <a-button style="margin-left: 8px">重置</a-button>
  72. <a @click="toggleAdvanced" style="margin-left: 8px">
  73. {{ advanced ? '收起' : '展开' }}
  74. <a-icon :type="advanced ? 'up' : 'down'"/>
  75. </a>
  76. </span>
  77. </a-form>
  78. </div>
  79. <s-table
  80. ref="table"
  81. size="default"
  82. :columns="columns"
  83. :data="loadData"
  84. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onChange }"
  85. >
  86. <template v-for="(col, index) in columns" v-if="col.scopedSlots" :slot="col.dataIndex" slot-scope="text, record, index">
  87. <div :key="index">
  88. <a-input
  89. v-if="record.editable"
  90. style="margin: -5px 0"
  91. :value="text"
  92. @change="e => handleChange(e.target.value, record.key, col)"
  93. />
  94. <template v-else>{{ text }}</template>
  95. </div>
  96. </template>
  97. <template slot="action" slot-scope="text, record, index">
  98. <div class='editable-row-operations'>
  99. <span v-if="record.editable">
  100. <a @click="() => save(record)" style="margin-right: 12px">Save</a>
  101. <a-popconfirm title='Sure to cancel?' @confirm="() => cancel(record)">
  102. <a>Cancel</a>
  103. </a-popconfirm>
  104. </span>
  105. <span v-else>
  106. <a @click="() => edit(record, index)">Edit</a>
  107. </span>
  108. </div>
  109. </template>
  110. </s-table>
  111. </a-card>
  112. </template>
  113. <script>
  114. import STable from '@/components/table/'
  115. export default {
  116. name: "TableList",
  117. components: {
  118. STable
  119. },
  120. data () {
  121. return {
  122. // 高级搜索 展开/关闭
  123. advanced: false,
  124. // 查询参数
  125. queryParam: {},
  126. // 表头
  127. columns: [
  128. {
  129. title: '规则编号',
  130. dataIndex: 'no'
  131. },
  132. {
  133. title: '描述',
  134. dataIndex: 'description',
  135. scopedSlots: { customRender: 'description' },
  136. },
  137. {
  138. title: '服务调用次数',
  139. dataIndex: 'callNo',
  140. sorter: true,
  141. needTotal: true,
  142. scopedSlots: { customRender: 'callNo' },
  143. // customRender: (text) => text + ' 次'
  144. },
  145. {
  146. title: '状态',
  147. dataIndex: 'status',
  148. needTotal: true,
  149. scopedSlots: { customRender: 'status' },
  150. },
  151. {
  152. title: '更新时间',
  153. dataIndex: 'updatedAt',
  154. sorter: true,
  155. scopedSlots: { customRender: 'updatedAt' },
  156. },
  157. {
  158. table: '操作',
  159. dataIndex: 'action',
  160. width: '150px',
  161. scopedSlots: { customRender: 'action' },
  162. }
  163. ],
  164. // 加载数据方法 必须为 Promise 对象
  165. loadData: parameter => {
  166. return this.$http.get('/service', {
  167. params: Object.assign(parameter, this.queryParam)
  168. }).then(res => {
  169. return res.result
  170. })
  171. },
  172. selectedRowKeys: [],
  173. selectedRows: []
  174. }
  175. },
  176. methods: {
  177. handleChange (value, key, column) {
  178. console.log(value, key, column)
  179. },
  180. edit (row) {
  181. row.editable = true
  182. row = Object.assign({}, row)
  183. this.$refs.table.updateEdit()
  184. },
  185. save (row) {
  186. delete row.editable
  187. this.$refs.table.updateEdit()
  188. },
  189. cancel (row) {
  190. delete row.editable
  191. this.$refs.table.updateEdit()
  192. },
  193. onChange (selectedRowKeys, selectedRows) {
  194. this.selectedRowKeys = selectedRowKeys
  195. this.selectedRows = selectedRows
  196. },
  197. toggleAdvanced () {
  198. this.advanced = !this.advanced
  199. },
  200. },
  201. watch: {
  202. /*
  203. 'selectedRows': function (selectedRows) {
  204. this.needTotalList = this.needTotalList.map(item => {
  205. return {
  206. ...item,
  207. total: selectedRows.reduce( (sum, val) => {
  208. return sum + val[item.dataIndex]
  209. }, 0)
  210. }
  211. })
  212. }
  213. */
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .search {
  219. margin-bottom: 54px;
  220. }
  221. .fold {
  222. width: calc(100% - 216px);
  223. display: inline-block
  224. }
  225. .operator {
  226. margin-bottom: 18px;
  227. }
  228. @media screen and (max-width: 900px) {
  229. .fold {
  230. width: 100%;
  231. }
  232. }
  233. </style>