CustomizeReport.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper" @keyup.enter="handleEnter">
  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.keyword" placeholder="请输入名称/类型名称" />
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8 || 24" :sm="24">
  12. <span class="table-page-search-submitButtons">
  13. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  14. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  15. </span>
  16. </a-col>
  17. </a-row>
  18. </a-form>
  19. </div>
  20. <div class="table-operator">
  21. <a-button v-if="$auth('customize-reports-add')" type="primary" icon="plus" @click="$refs.baseModal.base()">新增
  22. </a-button>
  23. <a-button
  24. style="margin-left: 8px"
  25. v-if="$auth('customize-reports-export')"
  26. type="primary"
  27. icon="download"
  28. @click="doExport">导出
  29. </a-button>
  30. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('customize-reports-del')">
  31. <a-menu slot="overlay">
  32. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  33. <a-menu-item key="1">
  34. <a-icon type="delete" />
  35. <a>删除</a></a-menu-item>
  36. </a-popconfirm>
  37. </a-menu>
  38. <a-button style="margin-left: 8px">
  39. 批量操作
  40. <a-icon type="down" />
  41. </a-button>
  42. </a-dropdown>
  43. </div>
  44. <s-table
  45. ref="table"
  46. size="default"
  47. rowKey="id"
  48. :columns="columns"
  49. :data="loadData"
  50. :alert="options.alert"
  51. :rowSelection="options.rowSelection"
  52. showPagination="auto"
  53. >
  54. <span slot="action" slot-scope="record">
  55. <template>
  56. <a @click="handleView(record)">查看</a>
  57. <operation-button
  58. v-if="$auth('customize-reports-edit')"
  59. @click="handleEdit(record)"
  60. >修改</operation-button>
  61. <operation-button
  62. @click="handlePreview(record)"
  63. >预览</operation-button>
  64. <operation-button
  65. v-if="$auth('customize-reports-del')"
  66. :type="2"
  67. title="是否要删除该条数据?"
  68. @confirm="batchDelete(record.id)">删除</operation-button>
  69. </template>
  70. </span>
  71. <span slot="interType" slot-scope="text">
  72. <badge
  73. :text="interTypeMap[text]" />
  74. </span>
  75. <span slot="echartType" slot-scope="text">
  76. <badge
  77. :text="echartTypeMap[text]" />
  78. </span>
  79. </s-table>
  80. <base-form ref="baseModal" @ok="handleOk" />
  81. <detail ref="detailModal" />
  82. </a-card>
  83. </template>
  84. <script>
  85. import { STable, Ellipsis } from '@/components'
  86. import BaseForm from './modules/BaseForm'
  87. import Detail from './modules/Detail'
  88. import {
  89. getCustomizeReportPage,
  90. deleteCustomizeReports,
  91. fetchCustomizeReport,
  92. exportCustomizeReport
  93. } from '@/api/customize/report'
  94. export default {
  95. name: 'CustomizeReportList',
  96. components: {
  97. STable,
  98. Ellipsis,
  99. BaseForm,
  100. Detail
  101. },
  102. data () {
  103. return {
  104. // 查询参数
  105. queryParam: {},
  106. // 表头
  107. columns: [
  108. {
  109. title: '序号',
  110. dataIndex: 'index',
  111. customRender: (text, record, index) => {
  112. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  113. }
  114. },
  115. {
  116. title: '自定义报表名称',
  117. dataIndex: 'name'
  118. },
  119. {
  120. title: '图形类别',
  121. dataIndex: 'echartType',
  122. scopedSlots: { customRender: 'echartType' }
  123. },
  124. /* {
  125. title: '报表检索条件',
  126. dataIndex: 'parameter'
  127. }, */
  128. {
  129. title: '报表接口类型',
  130. dataIndex: 'interType',
  131. scopedSlots: { customRender: 'interType' }
  132. },
  133. {
  134. title: '数据来源',
  135. dataIndex: 'sqlVal'
  136. },
  137. /* {
  138. title: '表格展示字段',
  139. dataIndex: 'columns'
  140. }, */
  141. /* {
  142. title: '创建人',
  143. dataIndex: 'createdUserName'
  144. }, */
  145. {
  146. title: '创建时间',
  147. dataIndex: 'createdTime'
  148. },
  149. {
  150. title: '操作',
  151. key: 'action',
  152. width: '200px',
  153. align: 'center',
  154. scopedSlots: { customRender: 'action' }
  155. }
  156. ],
  157. // 下拉框map
  158. echartTypeMap: [],
  159. interTypeMap: [],
  160. // 加载数据方法 必须为 Promise 对象
  161. loadData: parameter => {
  162. parameter = {
  163. ...parameter,
  164. ...this.queryParam,
  165. dataScope: {
  166. sortBy: 'desc',
  167. sortName: 'update_time'
  168. }
  169. }
  170. return getCustomizeReportPage(Object.assign(parameter, this.queryParam))
  171. .then(res => {
  172. return res.data
  173. })
  174. },
  175. selectedRowKeys: [],
  176. selectedRows: [],
  177. options: {
  178. alert: {
  179. show: true,
  180. clear: () => {
  181. this.selectedRowKeys = []
  182. }
  183. },
  184. rowSelection: {
  185. selectedRowKeys: this.selectedRowKeys,
  186. onChange: this.onSelectChange
  187. }
  188. },
  189. optionAlertShow: false
  190. }
  191. },
  192. created () {
  193. // 下拉框map
  194. this.echartTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOMIZE_REPORT_ECHART_TYPE)
  195. this.interTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOMIZE_REPORT_INTER_TYPE)
  196. },
  197. methods: {
  198. tableOption () {
  199. if (!this.optionAlertShow) {
  200. this.options = {
  201. alert: {
  202. show: true,
  203. clear: () => {
  204. this.selectedRowKeys = []
  205. }
  206. },
  207. rowSelection: {
  208. selectedRowKeys: this.selectedRowKeys,
  209. onChange: this.onSelectChange,
  210. getCheckboxProps: record => ({
  211. props: {
  212. disabled: false,
  213. name: record.id
  214. }
  215. })
  216. }
  217. }
  218. this.optionAlertShow = true
  219. } else {
  220. this.options = {
  221. alert: false,
  222. rowSelection: null
  223. }
  224. this.optionAlertShow = false
  225. }
  226. },
  227. batchDelete (id) {
  228. let ids = []
  229. if (this.BaseTool.String.isBlank(id)) {
  230. const length = this.selectedRows.length
  231. if (length === 0) {
  232. this.$message.info('请选择要删除的记录')
  233. return
  234. }
  235. ids = this.selectedRows.map(item => item.id)
  236. } else {
  237. ids = [id]
  238. }
  239. deleteCustomizeReports(ids).then(res => {
  240. this.$message.info('删除成功')
  241. this.handleOk()
  242. this.$refs.table.clearSelected()
  243. })
  244. },
  245. handleEdit (record) {
  246. fetchCustomizeReport({ id: record.id }).then(res => {
  247. const modal = this.$refs.baseModal
  248. modal.base(res.data)
  249. })
  250. },
  251. handlePreview (record) {
  252. console.log('JSON.stringify(record): ' + JSON.stringify(record))
  253. const text = this.$router.resolve({
  254. name: 'ChartReport',
  255. query: record
  256. })
  257. // 打开一个新的页面
  258. window.open(text.href, '_blank')
  259. },
  260. handleView (record) {
  261. fetchCustomizeReport({ id: record.id }).then(res => {
  262. const modal = this.$refs.detailModal
  263. modal.base(res.data)
  264. })
  265. },
  266. handleOk () {
  267. this.$refs.table.refresh()
  268. },
  269. onSelectChange (selectedRowKeys, selectedRows) {
  270. this.selectedRowKeys = selectedRowKeys
  271. this.selectedRows = selectedRows
  272. },
  273. resetSearchForm () {
  274. this.queryParam = {}
  275. this.$refs.table.refresh(true)
  276. },
  277. doExport () {
  278. const parameter = {
  279. ...this.queryParam
  280. }
  281. exportCustomizeReport(parameter).then(file => {
  282. this.BaseTool.Util.downLoadExportExcel(file)
  283. })
  284. },
  285. handleEnter () {
  286. this.$refs.table.refresh(true)
  287. }
  288. }
  289. }
  290. </script>