a4214c3e695eb85b66b2dac882964241530fe446.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <j-modal
  3. width="80%"
  4. :title="title"
  5. :visible.sync="editModalVisible"
  6. :fullscreen.sync="fullscreen"
  7. :switch-fullscreen="switchFullscreen"
  8. @cancel="handleCancleDbSync"
  9. :destroyOnClose="true"
  10. >
  11. <template slot="footer">
  12. <a-button @click="handleCancleDbSync">
  13. 关闭
  14. </a-button>
  15. <a-button type="primary" :loading="syncLoading" @click="handleDbSync" >确定</a-button>
  16. </template>
  17. <div class="table-page-search-wrapper warp">
  18. <a-form-model layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="formData" :rules="rules">
  19. <a-row :gutter="24">
  20. <a-col :xl="8" :lg="8" :md="8" :sm="24" >
  21. <a-form-model-item label="图表名称" prop="name">
  22. <a-input v-model="formData.name" placeholder="请输入图表名称"/>
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  26. <a-form-model-item label="编码" prop="code">
  27. <a-input v-model="formData.code" placeholder="请输入图表编码"/>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  31. <a-form-model-item label="展示模板">
  32. <a-select v-model="formData.displayTemplate" placeholder="请选择展示模板">
  33. <a-select-option value="tab">Tab风格</a-select-option>
  34. <a-select-option value="single">单排布局</a-select-option>
  35. <a-select-option value="double">双排布局</a-select-option>
  36. </a-select>
  37. </a-form-model-item>
  38. </a-col>
  39. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  40. <a-form-model-item label="X轴字段" prop="xaxisField">
  41. <a-input v-model="formData.xaxisField" placeholder="请输入X轴字段"/>
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  45. <a-form-model-item label="分组字段" prop="groupField">
  46. <a-select
  47. mode="tags"
  48. style="width: 100%"
  49. placeholder="请输入Y轴字段"
  50. :open="false"
  51. v-model="groupField"
  52. >
  53. </a-select>
  54. </a-form-model-item>
  55. </a-col>
  56. <a-col :xl="8" :lg="8" :md="8" :sm="24" >
  57. <a-form-model-item label="是否分组">
  58. <a-checkbox v-model="formData.isGroup" @change="isGroupChange"></a-checkbox>
  59. </a-form-model-item>
  60. </a-col>
  61. <a-col :xl="16" :lg="16" :md="16" :sm="24" :offset="8" v-if="!formData.isGroup">
  62. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="Y轴字段" prop="yaxisField">
  63. <a-input v-model="formData.yaxisField" placeholder="Y轴字段"/>
  64. </a-form-model-item>
  65. </a-col>
  66. <a-col :xl="8" :lg="8" :md="8" :sm="24" >
  67. <a-form-model-item label="数据类型">
  68. <j-dict-select-tag v-model="formData.dataType" :triggerChange="true" @change="graphDataTypeChange" placeholder="请选择数据类型" dict-code="online_graph_data_type"/>
  69. </a-form-model-item>
  70. </a-col>
  71. <a-col :xl="16" :lg="16" :md="16" :sm="24">
  72. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="图表类型" prop="graphType">
  73. <j-select-multiple
  74. v-model="formData.graphType"
  75. placeholder="请选择图表类型"
  76. :options="graphTypeDictOptions"
  77. />
  78. </a-form-model-item>
  79. </a-col>
  80. <a-col :offset="8" :xl="16" :lg="16" :md="16" :sm="24" v-if="formData.graphType && formData.graphType.split(',').indexOf('treeTable')>=0">
  81. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="pid" prop="pid">
  82. <a-input v-model="formData.pid" placeholder="请输入pid"/>
  83. </a-form-model-item>
  84. </a-col>
  85. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  86. <a-form-model-item label="是否X轴聚合">
  87. <a-checkbox :disabled="formData.dataType === 'sql'?false:true" v-model="formData.aggregate"></a-checkbox>
  88. </a-form-model-item>
  89. </a-col>
  90. <a-col :xl="16" :lg="16" :md="16" :sm="24">
  91. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="数据表格描述">
  92. <a-input v-model="formData.annotation" placeholder="请输入描述"/>
  93. </a-form-model-item>
  94. </a-col>
  95. <a-col :xl="8" :lg="8" :md="8" :sm="24">
  96. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="描述">
  97. <a-input v-model="formData.content" type="textarea" placeholder="请输入描述" />
  98. </a-form-model-item>
  99. </a-col>
  100. <template v-if="formData.dataType === 'bean'">
  101. <a-col :xl="16" :lg="16" :md="16" :sm="24" >
  102. <a-form-model-item :label-col="{span:3}" :wrapper-col="{span:21}" label="java" prop="beanPath" >
  103. <a-input v-model="formData.beanPath" type="text" placeholder="请输入java类" />
  104. </a-form-model-item>
  105. </a-col>
  106. </template>
  107. </a-row>
  108. </a-form-model>
  109. <a-form-model :rules="rules">
  110. <a-row :gutter="24">
  111. <template v-if="formData.dataType === 'sql'">
  112. <a-col :xl="24" :lg="24" :md="24" :sm="24" style="padding-left: 4px; padding-right: 4px;">
  113. <a-form-model-item label="查询SQL" style="margin-bottom: 4px;">
  114. <code-mirror-lite
  115. mode="sql"
  116. v-model="formData.cgrSql"
  117. ></code-mirror-lite>
  118. </a-form-model-item>
  119. </a-col>
  120. <a-col :xl="24" :lg="24" :md="24" :sm="24" style="padding-left: 12px; padding-right: 4px; text-align: right; margin-bottom: 24px;">
  121. <span style="float: right;overflow: hidden;">
  122. <a-button type="primary" @click="searchSQL">SQL解析</a-button>
  123. </span>
  124. </a-col>
  125. </template>
  126. <template v-else-if="formData.dataType === 'json'">
  127. <a-col :xl="24" :lg="24" :md="24" :sm="24" style="padding-left: 4px; padding-right: 4px;">
  128. <a-form-model-item label="数据JSON" prop="cgrSql" >
  129. <code-mirror-lite v-model="formData.cgrSql"></code-mirror-lite>
  130. </a-form-model-item>
  131. </a-col>
  132. </template>
  133. <a-col :xl="24" :lg="24" :md="24" :sm="24">
  134. <a-form-model-item label="JS增强">
  135. <code-mirror-lite v-model="formData.extendJs"></code-mirror-lite>
  136. </a-form-model-item>
  137. </a-col>
  138. </a-row>
  139. </a-form-model>
  140. <a-tabs defaultActiveKey="1">
  141. <a-tab-pane key="1" tab="列表字段">
  142. <config-table :extendData={diagramCode:formData.code} ref="configTable" :tableData="formData.diagramFieldConfigurationList"></config-table>
  143. </a-tab-pane>
  144. </a-tabs>
  145. </div>
  146. </j-modal>
  147. </template>
  148. <script>
  149. import JSelectMultiple from '@/components/jeecg/JSelectMultiple'
  150. import { postAction, putAction, postActionQs } from '@/api/manage'
  151. import { validateDuplicateValue } from '@/utils/util'
  152. import CodeMirrorLite from '@/components/CodeMirrorLite/CodeMirrorLite'
  153. import ConfigTable from '../components/ConfigTable'
  154. import { CHART_LIST } from '../utils/Utils'
  155. export default {
  156. name: 'OnlGraphreportHeadModal',
  157. components: {
  158. JSelectMultiple,
  159. CodeMirrorLite,
  160. ConfigTable
  161. },
  162. computed: {
  163. groupField: {// 分组字段双向绑定转换
  164. get: function() {
  165. return this.formData.groupField ? this.formData.groupField.split(',') : []
  166. },
  167. set: function(value) {
  168. this.formData.groupField = value.join(',')
  169. }
  170. }
  171. },
  172. data() {
  173. const isJson = function(str) {
  174. try {
  175. JSON.parse(str)
  176. } catch (e) {
  177. return false
  178. }
  179. return true
  180. }
  181. return {
  182. editModalVisible: false,
  183. title: '编辑',
  184. syncLoading: false,
  185. fullscreen: true,
  186. switchFullscreen: true,
  187. labelCol: { span: 6 },
  188. wrapperCol: { span: 18 },
  189. graphTypeDictOptions: CHART_LIST, // 图表类型字典
  190. selectedRowKeys: [],
  191. url: {
  192. list: '/online/cgform/head/list',
  193. edit: 'diagram/diagramConfiguration/edit',
  194. add: 'diagram/diagramConfiguration/add',
  195. parseSql: '/diagram/diagramConfiguration/parseSql'
  196. },
  197. rules: {
  198. name: [
  199. { required: true, message: '请输入图表名称', trigger: 'change' }
  200. ],
  201. code: [
  202. { required: true, message: '请输入图表编码', trigger: 'blur' },
  203. { validator: (rule, value, callback) => validateDuplicateValue('cs_diagram_config', 'code', value, this.formData.id, callback) }
  204. ],
  205. xaxisField: [
  206. { required: true, message: '请输入X轴字段', trigger: 'change' }
  207. ],
  208. yaxisField: [
  209. { required: true, message: '请输入Y轴字段', trigger: 'change' }
  210. ],
  211. graphType: [
  212. { required: true, message: '请选择图表类型', trigger: 'change' }
  213. ],
  214. cgrSql: [
  215. { validator: isJson, message: 'JSON格式不正确', trigger: 'change' }
  216. ],
  217. pid: [
  218. { required: true, message: '请输入pid', trigger: 'change' }
  219. ],
  220. groupField: [
  221. { message: '请输入分组字段', trigger: 'change' }
  222. ],
  223. beanPath: [
  224. { required: true, message: '请输入Java', trigger: 'change' }
  225. ]
  226. },
  227. formData: {
  228. 'isCombination': '',
  229. 'displayTemplate': '',
  230. 'code': '',
  231. 'graphType': '',
  232. 'dataType': 'sql',
  233. 'yaxisField': '',
  234. 'updateTime': '',
  235. 'content': null,
  236. 'cgrSql': '',
  237. 'createBy': '',
  238. 'extendJs': null,
  239. 'createTime': '',
  240. 'updateBy': '',
  241. 'name': '',
  242. 'yaxisText': '',
  243. 'id': null,
  244. 'pid': null,
  245. 'xaxisField': '',
  246. 'aggregate': false,
  247. 'annotation': '',
  248. 'groupField': '',
  249. 'isGroup': true,
  250. 'beanPath': '',
  251. 'diagramFieldConfigurationList': []
  252. },
  253. newFormData: {// 新增用数据
  254. 'isCombination': '',
  255. 'displayTemplate': 'tab',
  256. 'code': '',
  257. 'graphType': '',
  258. 'dataType': 'json',
  259. 'yaxisField': '',
  260. 'updateTime': '',
  261. 'content': null,
  262. 'cgrSql': '',
  263. 'createBy': '',
  264. 'extendJs': '',
  265. 'createTime': '',
  266. 'updateBy': '',
  267. 'name': '',
  268. 'yaxisText': '',
  269. 'id': null,
  270. 'pid': null,
  271. 'xaxisField': '',
  272. 'aggregate': false,
  273. 'annotation': '',
  274. 'isGroup': true,
  275. 'diagramFieldConfigurationList': []
  276. },
  277. disableSubmit: false
  278. }
  279. },
  280. methods: {
  281. handleCancleDbSync() { // 关闭
  282. this.editModalVisible = false
  283. },
  284. edit(record) {
  285. var that = this
  286. const record_ = JSON.parse(JSON.stringify(record))
  287. Object.keys(that.formData).forEach(function(key) {
  288. that.formData[key] = record_[key]
  289. })
  290. this.editModalVisible = true
  291. },
  292. add() {
  293. var that = this
  294. const record_ = JSON.parse(JSON.stringify(that.newFormData))
  295. Object.keys(that.formData).forEach(function(key) {
  296. that.formData[key] = record_[key]
  297. })
  298. this.editModalVisible = true
  299. },
  300. handleDbSync() { // 弹窗点击确定
  301. const configTable = this.$refs.configTable.getTableData()
  302. this.formData.diagramFieldConfigurationList = configTable
  303. this.$refs['ruleForm'].validate(valid => {
  304. if (valid) {
  305. this.updateData()
  306. } else {
  307. console.log('error submit!!')
  308. return false
  309. }
  310. })
  311. },
  312. updateData(params) { // 保存提交数据
  313. if (this.formData.id) {
  314. putAction(this.url.edit, this.formData).then((res) => {
  315. if (res.success) {
  316. this.$message.success(res.message)
  317. this.editModalVisible = false
  318. this.$emit('modalFormOk')
  319. } else {
  320. this.$message.warning(res.message)
  321. }
  322. }).finally(() => {
  323. // this.loading = false
  324. })
  325. } else {
  326. postAction(this.url.add, this.formData).then((res) => {
  327. if (res.success) {
  328. this.$message.success(res.message)
  329. this.editModalVisible = false
  330. this.$emit('modalFormOk')
  331. } else {
  332. this.$message.warning(res.message)
  333. }
  334. }).finally(() => {
  335. // this.loading = false
  336. })
  337. }
  338. },
  339. searchSQL() { // SQL解析
  340. postActionQs(this.url.parseSql, { sql: this.formData.cgrSql }).then((res) => {
  341. if (res.code === 200) {
  342. this.$message.info(res.message)
  343. var that = this
  344. this.$refs.configTable.clearTableData()
  345. res.result.forEach(function(item, i) {
  346. that.$refs.configTable.handleAddGraphRepoart({
  347. fieldName: item,
  348. orderNum: i
  349. })
  350. })
  351. } else {
  352. this.$message.error(res.message)
  353. }
  354. })
  355. },
  356. graphDataTypeChange(val) {
  357. this.formData.dataType = val
  358. if (val === 'json') {
  359. this.formData.aggregate = false
  360. }
  361. },
  362. isGroupChange(event) { // 是否分组切换
  363. const graphType = []
  364. if (!event.target.checked) {
  365. var list = this.formData.graphType.split(',')
  366. list.forEach((item, i) => {
  367. if (['bar', 'line', 'barStack', 'transverseBarMuiltid'].indexOf(item) >= 0) {
  368. graphType.push(item)
  369. }
  370. })
  371. this.formData.graphType = graphType.join(',')
  372. }
  373. this.graphTypeDictOptions.forEach((item, i) => {
  374. item.disabled = ['bar', 'line', 'barStack', 'transverseBarMuiltid'].indexOf(item.value) < 0 && !event.target.checked
  375. })
  376. }
  377. }
  378. }
  379. </script>
  380. <style lang="less">
  381. .warp .ant-select{
  382. width: 100%;
  383. }
  384. .warp .table-operator{
  385. margin-bottom: 10px;
  386. }
  387. .ant-card-body .warp {
  388. padding: 10px;
  389. }
  390. .warp .table-operator .ant-btn{
  391. margin: 0px 8px 0 0 !important;
  392. }
  393. .ant-card-body .warp .table-operator{
  394. margin-bottom:10px !important;
  395. }
  396. </style>