93406d1f3887c189d2e46ad37934124ea7069e22.svn-base 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <template>
  2. <div>
  3. <el-card body-style="padding:0;" style="margin-bottom: 20px;" class="panel-header">
  4. <div slot="header" style="display: flex; justify-content:space-between;">
  5. <span>
  6. <span class="back-button" @click="$router.push({ name: 'BoardEchartManagement', params: { tab: 'second' } })">
  7. <i class="el-icon-back" />
  8. <span>返回</span>
  9. </span>
  10. <span v-if="this.$route.params.id == 'create'">新增图表</span>
  11. <span v-if="this.$route.params.isEdit == 'view'">查看图表</span>
  12. <span v-if="this.$route.params.isEdit == 'edit' && this.$route.params.id != 'create'">编辑图表</span>
  13. </span>
  14. <span>
  15. <el-button v-if="false" size="mini" type="primary" style="float: right;margin:0 10px 0 0;" icon="el-icon-download" @click="handleDownload" />
  16. <el-button v-if="this.$route.params.isEdit == 'edit'" size="mini" type="primary" style="float: right;margin:0 10px 0 0;" @click="handleLinkDB">添加到仪表盘</el-button>
  17. <el-button v-if="this.$route.params.isEdit == 'edit'" size="mini" type="primary" style="float: right;margin:0 10px 0 0;" icon="el-icon-save" @click="handleSave">保存</el-button>
  18. <el-button v-if="false" size="mini" type="primary" style="float: right;margin:0 10px 0 0;" @click="$router.replace(`/chartpanel/create`)">创建新的图表</el-button>
  19. </span>
  20. </div>
  21. </el-card>
  22. <div class="app-container" style="display: flex;">
  23. <el-card id="dataPanel" style="width:300px;margin-right: 20px;text-align:center;">
  24. <data-panel ref="dataPanel" :result-loading="loading" :data-src="dataSrc" :isEdit="this.$route.params.isEdit || this.$store.state.user.dashchartidisedit" @change="handleDataSrcChange" />
  25. </el-card>
  26. <!-- 图表部分 -->
  27. <el-card style="width: 100%;" body-style="padding: 10px 20px;">
  28. <div class="form-wrapper">
  29. <el-form id="formPanel" size="mini" class="analysis-form">
  30. <el-form-item id="dimensionInput" label="维度">
  31. <draggable v-model="sharedState.dimensions" :group="{name: 'col',pull: true, put: true}" class="draggable-wrapper" @change="handleDimensionChange">
  32. <el-tag v-for="col in sharedState.dimensions" :key="col.Column" class="draggable-item" size="small" closable @close="handleCloseDimensionTag(col)">
  33. {{ col.Comment }}
  34. </el-tag>
  35. </draggable>
  36. </el-form-item>
  37. <!-- <el-form-item id="fieldInput" label="数值">
  38. <draggable v-model="sharedState.caculCols" :group="{name: 'col',pull: true, put: true}" class="draggable-wrapper" @change="handleColChange">
  39. <el-tag v-for="col in sharedState.caculCols" :key="col.Column" size="small" closable class="selected-field" @close="handleCloseColTag(col)">
  40. <el-select v-model="col.calculFunc" class="draggable-item" size="mini" closable style="background: rgba(0,0,0,0);">
  41. <el-option v-for="(item, optIndex) in col.availableFunc" :key="optIndex" :label="`${col.Comment}(${item.name})`" :value="item.func" />
  42. </el-select>
  43. </el-tag>
  44. </draggable>
  45. </el-form-item> -->
  46. <el-form-item id="fieldInput" label="数值(主)">
  47. <draggable v-model="sharedState.caculCols" :group="{name: 'col',pull: true, put: true}" class="draggable-wrapper" @change="handleColChange">
  48. <el-tag v-for="col in sharedState.caculCols" :key="col.Column" size="small" closable class="selected-field" @close="handleCloseColTag(col)">
  49. <el-select v-model="col.calculFunc" class="draggable-item" size="mini" closable style="background: rgba(0,0,0,0);">
  50. <el-option v-for="(item, optIndex) in col.availableFunc" :key="optIndex" :label="`${col.Comment}(${item.name})`" :value="item.func" />
  51. </el-select>
  52. </el-tag>
  53. </draggable>
  54. </el-form-item>
  55. <el-form-item id="fieldInput2" label="数值(次)">
  56. <draggable v-model="sharedState.caculCols2" :group="{name: 'col',pull: true, put: true}" class="draggable-wrapper" @change="handleColChange2">
  57. <el-tag v-for="col in sharedState.caculCols2" :key="col.Column" size="small" closable class="selected-field" @close="handleCloseColTag2(col)">
  58. <el-select v-model="col.calculFunc" class="draggable-item" size="mini" closable style="background: rgba(0,0,0,0);">
  59. <el-option v-for="(item, optIndex) in col.availableFunc" :key="optIndex" :label="`${col.Comment}(${item.name})`" :value="item.func" />
  60. </el-select>
  61. </el-tag>
  62. </draggable>
  63. </el-form-item>
  64. <orderPanel v-model="orderByStrs" />
  65. <filterPanel :filters.sync="currentFilters" :disabled="!allSelected || allSelected.length===0" @change="handleAddFilter" />
  66. <el-form-item>
  67. <div class="limit-input">
  68. <span v-show="!editLimit">
  69. {{ $t('chart.limit', [limit]) }}
  70. <el-button type="text" @click="editLimit=true">{{ $t('common.edit') }}</el-button>
  71. </span>
  72. <span v-show="editLimit">
  73. <el-input-number v-model="limit" :disabled="loading" size="mini" style="width:100px;" @blur="editLimit=false" :max="60000" />
  74. <el-button size="mini" @click="editLimit=false">确认</el-button>
  75. </span>
  76. </div>
  77. </el-form-item>
  78. </el-form>
  79. <el-form class="chart-form" size="mini" label-position="top">
  80. <el-form-item label="图表名称:">
  81. <el-input v-model="chartName" size="mini" :placeholder="$t('chart.namePlaceholder')" />
  82. </el-form-item>
  83. <el-form-item label="图表描述:">
  84. <el-input v-model="chartDesc" size="mini" :placeholder="$t('chart.descPlaceholder')" />
  85. </el-form-item>
  86. </el-form>
  87. </div>
  88. <!-- 图表内容展现主体 -->
  89. <visualize-panel id="vizPanel" v-loading="loading" :data="result" :chart-type.sync="chartType" :schema="allSelected" v-if="sonRefresh" />
  90. </el-card>
  91. </div>
  92. <el-dialog :title="$t('chart.myChart')" :visible.sync="showMyCharts">
  93. <el-table :data="myChartList">
  94. <el-table-column :label="$t('chart.chartName')" width="200" prop="chart_name" />
  95. <el-table-column :label="$t('chart.chartDesc')" prop="desc" />
  96. <el-table-column :label="$t('common.operation')" width="200" align="center">
  97. <template slot-scope="scope">
  98. <el-button size="mini" type="primary" icon="el-icon-edit" @click="switchChart(scope.row)">
  99. {{ $t('common.edit') }}
  100. </el-button>
  101. <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteChart(scope.row)">
  102. {{ $t('common.delete') }}
  103. </el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <span slot="footer" class="dialog-footer">
  108. <el-button type="primary" size="mini" @click="showMyCharts = false">{{ $t('common.close') }}</el-button>
  109. </span>
  110. </el-dialog>
  111. <el-dialog title="仪表盘列表" :visible.sync="showDashboards" width="390px" style="text-align:center">
  112. <p style="margin-right:110px;">请选择仪表盘</p>
  113. <div style="margin-bottom:20px;">
  114. <el-select v-model="selectedDb" size="small">
  115. <el-option v-for="item in dashboardList" :key="item.objectId" :label="item.name" :value="item.dashboard_id" />
  116. </el-select>
  117. </div>
  118. <span slot="footer" class="dialog-footer">
  119. <el-button type="primary" size="small" @click="showDashboards = false">取消</el-button>
  120. <el-button type="primary" size="small" @click="linkDb">添加到仪表盘</el-button>
  121. </span>
  122. </el-dialog>
  123. <!-- <el-tooltip content="帮助中心" placement="top"> -->
  124. <el-dropdown v-if="false" class="help-center-wrapper" placement="top" size="mini" @command="handleHelp">
  125. <div class="help-center">
  126. <i class="el-icon-question" />
  127. </div>
  128. <el-dropdown-menu slot="dropdown" size="mini">
  129. <el-dropdown-item command="guide">
  130. {{ this.$t('common.openGuide') }}
  131. </el-dropdown-item>
  132. </el-dropdown-menu>
  133. </el-dropdown>
  134. <!-- </el-tooltip 1> -->
  135. </div>
  136. </template>
  137. <script>
  138. import draggable from 'vuedraggable'
  139. import Driver from 'driver.js' // import driver.js
  140. import 'driver.js/dist/driver.min.css' // import driver.js css
  141. import { GetDataByName, ExeSqlJiade, PostDataByName, dashboardListJiade } from '@/api/common'
  142. import filterPanel from './components/filterPanel'
  143. import orderPanel from './components/orderPanel'
  144. import visualizePanel from './components/visualizePanel'
  145. import dataPanel from './components/dataPanel'
  146. import Cookies from 'js-cookie'
  147. import { createChart, updateChart, getChartById, chartList, deleteChart } from '@/api/chart'
  148. import { dashboardList, addChartToDB, dbByChart } from '@/api/dashboard'
  149. import exeSql from '@/api/exeSql'
  150. import { parseTime } from '@/utils'
  151. import { buildSqlSentence } from '@/utils/buildSentence'
  152. import steps from './guideSteps'
  153. import store from './store'
  154. const driver = new Driver()
  155. export default {
  156. inject: ['reload'],
  157. name: 'ChartPanel',
  158. components: { visualizePanel, dataPanel, draggable, filterPanel, orderPanel },
  159. data() {
  160. return {
  161. sonRefresh: true,
  162. loading: false,
  163. result: [],
  164. dataSrc: {},
  165. limit: 200,
  166. orderByStrs: [],
  167. filterStr: undefined,
  168. editLimit: false,
  169. currentFilters: [],
  170. sharedState: store.state,
  171. chartType: 'table',
  172. chartName: undefined,
  173. chartDesc: undefined,
  174. showMyCharts: false,
  175. myChartList: [],
  176. showDashboards: false,
  177. dashboardList: [],
  178. selectedDb: undefined,
  179. linkedDbIds: [],
  180. execInstance: null,
  181. LastInsertId: "",
  182. isSaving: false
  183. }
  184. },
  185. computed: {
  186. // allSelected() {
  187. // return store.state.dimensions.concat(store.state.caculCols)
  188. // },
  189. allSelected() {
  190. return store.state.dimensions.concat(store.state.caculCols).concat(store.state.caculCols2)
  191. },
  192. sqlSentence() {
  193. return buildSqlSentence({
  194. dataSrc: this.dataSrc.table,
  195. selectedCalcul: this.sharedState.caculCols,
  196. selectedCalcul2: this.sharedState.caculCols2,
  197. selectedDimension: this.sharedState.dimensions,
  198. orderByStrs: this.orderByStrs,
  199. filterStr: this.filterStr,
  200. limit: this.limit
  201. })
  202. }
  203. },
  204. watch: {
  205. sqlSentence(value) {
  206. if (value) {
  207. this.fetchData(value)
  208. } else {
  209. this.result = []
  210. }
  211. },
  212. '$route.params.id': {
  213. immediate: true,
  214. handler() {
  215. console.log("this.$route.params.id=====================", this.$route.params.id)
  216. if (this.$route.params.id !== 'create') {
  217. console.log('我是编辑图表哦~~~')
  218. console.log('this.$route.params.id', this.$route.params.id)
  219. console.log('localStorage==========', localStorage.getItem('ChartPanelIsEditId'))
  220. console.log('this.$store.state.user.dashchartid==========', this.$store.state.user.dashchartid)
  221. if (this.$route.params.id) {
  222. console.log('我是编辑图表第一次跳转~~~')
  223. var send_data = {
  224. name: 'getChartDetail',
  225. parammaps: {
  226. pastureid: Cookies.get('pastureid'),
  227. id: this.$route.params.id
  228. }
  229. }
  230. GetDataByName(send_data).then(response => {
  231. console.log('图表数据', response.data.list)
  232. const chart = response.data.list[0]
  233. this.chartName = chart.chart_name
  234. this.chartDesc = chart.desc
  235. const content = JSON.parse(chart.content) || {}
  236. this.dataSrc.table = content.dataSrc
  237. this.dataSrc.source_id = chart.source_id
  238. this.chartType = content.chartType
  239. this.limit = content.limit || 200
  240. this.currentFilters = content.filters
  241. this.orderByStrs = content.orderByStrs
  242. store.setCaculColsAction(content.selectedCalcul)
  243. store.setCaculColsAction2(content.selectedCalcul2)
  244. store.setDimensionsAction(content.selectedDimension)
  245. this.$refs.dataPanel.initWithDataSrc(this.dataSrc)
  246. })
  247. } else {
  248. console.log('我是编辑图表切换跳转~~~')
  249. var send_data = {
  250. name: 'getChartDetail',
  251. parammaps: {
  252. pastureid: Cookies.get('pastureid'),
  253. // id: this.$route.params.id
  254. id: localStorage.getItem('ChartPanelIsEditId')
  255. }
  256. }
  257. GetDataByName(send_data).then(response => {
  258. console.log('图表数据', response.data.list)
  259. const chart = response.data.list[0]
  260. this.chartName = chart.chart_name
  261. this.chartDesc = chart.desc
  262. const content = JSON.parse(chart.content) || {}
  263. this.dataSrc.table = content.dataSrc
  264. this.dataSrc.source_id = chart.source_id
  265. this.chartType = content.chartType
  266. this.limit = content.limit || 200
  267. this.currentFilters = content.filters
  268. this.orderByStrs = content.orderByStrs
  269. store.setCaculColsAction(content.selectedCalcul)
  270. store.setCaculColsAction2(content.selectedCalcul2)
  271. store.setDimensionsAction(content.selectedDimension)
  272. this.$refs.dataPanel.initWithDataSrc(this.dataSrc)
  273. })
  274. }
  275. } else {
  276. console.log('我是新增图标哦~~~')
  277. this.chartName = undefined
  278. this.chartDesc = undefined
  279. store.setCaculColsAction([])
  280. store.setCaculColsAction2([])
  281. store.setDimensionsAction([])
  282. this.$nextTick(() => {
  283. this.$refs.dataPanel.initWithDataSrc()
  284. })
  285. }
  286. }
  287. }
  288. },
  289. created() {
  290. },
  291. methods: {
  292. // fetchData(sqlSentence) {
  293. // if (this.loading) {
  294. // this.execInstance && this.execInstance.cancel()
  295. // }
  296. // this.loading = true
  297. // this.execInstance = exeSql()
  298. // this.execInstance.fetch({ source_id: this.dataSrc.source_id, sql: sqlSentence }).then(resp => {
  299. // this.loading = false
  300. // this.result = resp.data
  301. // })
  302. // },
  303. fetchData(sqlSentence) {
  304. if (this.loading) {
  305. this.execInstance && this.execInstance.cancel()
  306. }
  307. this.loading = true
  308. this.execInstance = exeSql()
  309. this.sharedState.caculCols2.map(function (i) {
  310. return (i.is_second = true)
  311. })
  312. const obj = {
  313. dataSrc: this.dataSrc.table,
  314. source_id: this.dataSrc.source_id,
  315. orderByStrs: this.orderByStrs,
  316. limit: this.limit,
  317. selectedCalcul: this.sharedState.caculCols,
  318. selectedCalcul2: this.sharedState.caculCols2,
  319. selectedDimension: this.sharedState.dimensions,
  320. chartType: this.chartType,
  321. filters: this.currentFilters
  322. }
  323. var send_data = { source_id: this.dataSrc.source_id, content: obj, pastureid: Cookies.get('pastureid') }
  324. ExeSqlJiade(send_data).then(response => {
  325. console.log('ExeSql发的数据======', send_data)
  326. console.log('图的数据', response.data.list)
  327. if (response.data !== null) {
  328. console.log('维度+数值获得的数据', Array.isArray(response.data))
  329. //判断是不是数组!result无论有没有值都必须是数组格式,不然会报错!
  330. if (Array.isArray(response.data)) {
  331. this.loading = false
  332. this.result = response.data
  333. } else {
  334. this.loading = false
  335. this.result = []
  336. }
  337. } else {
  338. this.loading = false
  339. this.result = []
  340. }
  341. })
  342. },
  343. handleDataSrcChange(value) {
  344. console.log('dataSrc======================', value)
  345. this.dataSrc = value
  346. store.setCaculColsAction([])
  347. store.setCaculColsAction2([])
  348. store.setDimensionsAction([])
  349. this.filterStr = undefined
  350. this.orderByStrs = []
  351. },
  352. handleColChange(evt) {
  353. if (evt.added) {
  354. store.addCaculColAction(evt.added.element)
  355. }
  356. },
  357. handleColChange2(evt) {
  358. if (evt.added) {
  359. store.addCaculColAction2(evt.added.element)
  360. }
  361. },
  362. // handleDimensionChange(evt) {
  363. // console.log('handleDimensionChange的evt', evt)
  364. // if (evt.added) {
  365. // store.addDimensionAction(evt.added.element)
  366. // }
  367. // },
  368. handleDimensionChange(evt) {
  369. console.log('this.sharedState.dimensions', this.sharedState.dimensions)
  370. if (evt.added) {
  371. store.addDimensionAction(evt.added.element)
  372. }
  373. if (evt.moved) {
  374. this.sonRefresh = false;
  375. this.$nextTick(() => {
  376. this.sonRefresh = true;
  377. });
  378. }
  379. },
  380. handleCloseColTag(col) {
  381. store.deleteCaculColAction(col)
  382. },
  383. handleCloseColTag2(col) {
  384. store.deleteCaculColAction2(col)
  385. },
  386. handleCloseDimensionTag(col) {
  387. store.deleteDimensionAction(col)
  388. },
  389. handleAddFilter(value) {
  390. this.filterStr = value
  391. },
  392. // 保存
  393. // handleSave() {
  394. // if (!this.chartName) {
  395. // this.$message({
  396. // type: 'warning',
  397. // message: this.$t('chart.chartNameWarning')
  398. // })
  399. // return
  400. // }
  401. // const chartId = this.$route.params.id === 'create' ? undefined : this.$route.params.id
  402. // const obj = {
  403. // dataSrc: this.dataSrc.table,
  404. // source_id: this.dataSrc.source_id,
  405. // orderByStrs: this.orderByStrs,
  406. // limit: this.limit,
  407. // selectedCalcul: this.sharedState.caculCols,
  408. // selectedDimension: this.sharedState.dimensions,
  409. // chartType: this.chartType,
  410. // filters: this.currentFilters
  411. // }
  412. // const data = {
  413. // id: chartId,
  414. // chart_name: this.chartName,
  415. // source_id: this.dataSrc.source_id,
  416. // desc: this.chartDesc,
  417. // content: obj
  418. // }
  419. // if (chartId) {
  420. // updateChart(data).then(resp => {
  421. // this.$message({
  422. // type: 'success',
  423. // message: this.$t('common.saveSuccess')
  424. // })
  425. // })
  426. // } else {
  427. // createChart(data).then(resp => {
  428. // // console.log(resp)
  429. // this.$router.replace(`/chartpanel/${resp.data.id}`)
  430. // this.$message({
  431. // type: 'success',
  432. // message: this.$t('common.saveSuccess')
  433. // })
  434. // })
  435. // }
  436. // },
  437. handleSave() {
  438. if (!this.chartName) {
  439. this.$message({
  440. type: 'warning',
  441. message: this.$t('chart.chartNameWarning')
  442. })
  443. return
  444. }
  445. // const chartId = this.$route.params.id === 'create' ? undefined : this.$route.params.id
  446. const chartId = localStorage.getItem('ChartPanelIsEditId') === 'create' ? undefined : localStorage.getItem('ChartPanelIsEditId')
  447. const obj = {
  448. dataSrc: this.dataSrc.table,
  449. source_id: this.dataSrc.source_id,
  450. orderByStrs: this.orderByStrs,
  451. limit: this.limit,
  452. selectedCalcul: this.sharedState.caculCols,
  453. selectedCalcul2: this.sharedState.caculCols2,
  454. selectedDimension: this.sharedState.dimensions,
  455. chartType: this.chartType,
  456. filters: this.currentFilters
  457. }
  458. const data = {
  459. name: 'insertChart',
  460. parammaps: {
  461. id: chartId,
  462. cname: this.chartName,
  463. source_id: this.dataSrc.source_id,
  464. desc: this.chartDesc,
  465. display: this.chartDesc,
  466. pastureid: Cookies.get('pastureid'),
  467. empid: Cookies.get('employeid'),
  468. emp: Cookies.get('employename'),
  469. content: obj
  470. }
  471. }
  472. var send_data2 = {
  473. name: 'updateChartV2',
  474. parammaps: {
  475. id: chartId,
  476. cname: this.chartName,
  477. source_id: this.dataSrc.source_id,
  478. desc: this.chartDesc,
  479. display: this.chartDesc,
  480. pastureid: Cookies.get('pastureid'),
  481. empid: Cookies.get('employeid'),
  482. emp: Cookies.get('employename'),
  483. content: obj
  484. }
  485. }
  486. this.isSaving = true
  487. if (chartId) {
  488. PostDataByName(send_data2).then(res => {
  489. console.log('编辑保存发送参数', data)
  490. if (res.msg == 'ok') {
  491. this.$message({
  492. type: 'success',
  493. message: this.$t('common.saveSuccess')
  494. })
  495. } else {
  496. this.$message({ type: 'error', message: '保存失败,请不要输入已有的图表名称!' })
  497. }
  498. })
  499. } else {
  500. PostDataByName(data).then(res => {
  501. console.log('新增保存发送参数', data)
  502. if (res.msg == 'ok') {
  503. this.$message({
  504. type: 'success',
  505. message: this.$t('common.saveSuccess')
  506. })
  507. this.LastInsertId = res.data.LastInsertId
  508. } else {
  509. this.$message({ type: 'error', message: '保存失败,请不要输入已有的图表名称!' })
  510. }
  511. })
  512. // createChart(data).then(resp => {
  513. // // console.log(resp)
  514. // this.$router.replace(`/chartpanel/${resp.data.id}`)
  515. // this.$message({
  516. // type: 'success',
  517. // message: this.$t('common.saveSuccess')
  518. // })
  519. // })
  520. }
  521. },
  522. handleLinkDB() {
  523. this.showDashboards = true
  524. var send_data = {
  525. name: 'getdashboards',
  526. parammaps: {
  527. pastureid: Cookies.get('pastureid'),
  528. empid: Cookies.get('employeid'),
  529. emp: Cookies.get('employename')
  530. }
  531. }
  532. dashboardListJiade(send_data).then(resp => {
  533. console.log('看板列表数据:', resp)
  534. this.dashboardList = resp.data.list
  535. })
  536. },
  537. getDbByChart(id) {
  538. dbByChart(id).then(resp => {
  539. this.linkedDbIds = resp.data || []
  540. })
  541. },
  542. isDbDisbaled(db) {
  543. return !!this.linkedDbIds.find(id => id === db.objectId)
  544. },
  545. linkDb() {
  546. this.showDashboards = false
  547. console.log(this.$route.params.id)
  548. console.log('仪表盘列表ID:', this.selectedDb)
  549. // var chartid1 = this.$route.params.id
  550. // if (chartid1 == "create") {
  551. // chartid1 = this.LastInsertId
  552. // } else {
  553. // chartid1 = this.$route.params.id
  554. // }
  555. var chartid1 = localStorage.getItem('ChartPanelIsEditId')
  556. if (chartid1 == "create") {
  557. chartid1 = this.LastInsertId
  558. } else {
  559. chartid1 = localStorage.getItem('ChartPanelIsEditId')
  560. }
  561. // var chartid1 = localStorage.getItem('ChartPanelIsEditId')
  562. // if (chartid1 == "create") {
  563. // chartid1 = this.LastInsertId
  564. // } else {
  565. // chartid1 = localStorage.getItem('ChartPanelIsEditId')
  566. // }
  567. const data = {
  568. name: 'insertdashboard_chart',
  569. parammaps: {
  570. did: this.selectedDb,
  571. cid: chartid1,
  572. pastureid: Cookies.get('pastureid')
  573. }
  574. }
  575. PostDataByName(data).then(response => {
  576. console.log('看板保存发送参数', data)
  577. this.$message({
  578. type: 'success',
  579. message: this.$t('common.saveSuccess')
  580. })
  581. })
  582. },
  583. viewAllChart() {
  584. this.showMyCharts = true
  585. // chartList().then(resp => {
  586. // this.myChartList = resp.data
  587. // })
  588. this.myChartList = [{ 'name': 'kook', 'desc': '', 'content': '{"layout": [{"id": "035573f4-bf71-4472-814a-f1747b6bd8e0", "x": 0, "y": 7, "w": 5, "h": 6, "i": "035573f4-bf71-4472-814a-f1747b6bd8e0", "moved": false, "yOffSet": 13, "xOffSet": 5, "bottomLine": [[0, 13], [5, 13]], "topLine": [[0, 7], [5, 7]]}, {"id": "02c012be-db57-431b-b9aa-40d1640a2592", "x": 2, "y": 29, "w": 7, "h": 6, "i": "02c012be-db57-431b-b9aa-40d1640a2592", "yOffSet": 35, "xOffSet": 9, "bottomLine": [[2, 35], [9, 35]], "topLine": [[2, 29], [9, 29]], "moved": false}, {"id": "087df61d-b02e-49a5-a954-b2d9124df685", "x": 6, "y": 0, "w": 7, "h": 7, "i": "087df61d-b02e-49a5-a954-b2d9124df685", "moved": false, "yOffSet": 7, "xOffSet": 13, "bottomLine": [[6, 7], [13, 7]], "topLine": [[6, 0], [13, 0]]}, {"id": "045ad6b0-8f7e-47db-92a7-8c4a31b7683d", "x": 5, "y": 16, "w": 10, "h": 6, "i": "045ad6b0-8f7e-47db-92a7-8c4a31b7683d", "moved": false, "yOffSet": 22, "xOffSet": 15, "bottomLine": [[5, 22], [15, 22]], "topLine": [[5, 16], [15, 16]]}, {"id": "182d02ef-ced5-4ded-a648-630c94f4a790", "x": 9, "y": 22, "w": 9, "h": 9, "i": "182d02ef-ced5-4ded-a648-630c94f4a790", "moved": false, "yOffSet": 31, "xOffSet": 18, "bottomLine": [[9, 31], [18, 31]], "topLine": [[9, 22], [18, 22]]}, {"id": "0755ae6e-6869-4e09-8630-62dd3118a2fc", "x": 0, "y": 0, "w": 6, "h": 7, "i": "0755ae6e-6869-4e09-8630-62dd3118a2fc", "moved": false, "yOffSet": 7, "xOffSet": 6, "bottomLine": [[0, 7], [6, 7]], "topLine": [[0, 0], [6, 0]]}, {"id": "3e4408f1-67c2-45c7-8315-136a6eec6980", "x": 5, "y": 22, "w": 4, "h": 7, "i": "3e4408f1-67c2-45c7-8315-136a6eec6980", "moved": false, "yOffSet": 29, "xOffSet": 9, "bottomLine": [[5, 29], [9, 29]], "topLine": [[5, 22], [9, 22]]}, {"id": "00af7fdb-b486-4855-ac7c-85014d283f2c", "x": 5, "y": 7, "w": 5, "h": 9, "i": "00af7fdb-b486-4855-ac7c-85014d283f2c", "moved": false, "yOffSet": 16, "xOffSet": 10, "bottomLine": [[5, 16], [10, 16]], "topLine": [[5, 7], [10, 7]]}, {"id": "3e39e265-684b-4d62-be3c-4613fd8730cd", "x": 14, "y": 7, "w": 8, "h": 9, "i": "3e39e265-684b-4d62-be3c-4613fd8730cd", "moved": false}]}', 'is_private': true, 'status': 1, 'creator': 1, 'created_at': '2020-05-13T06:08:39.438Z', 'updated_at': '2020-09-14T07:48:58.477Z', 'dashboard_id': 'dd02cfe9-8ee9-48fa-83b3-98b604d87b57' }]
  589. },
  590. switchChart(chart) {
  591. this.$confirm(this.$t('chart.beforeLeaveConfirm'), this.$t('common.confirm')).then(() => {
  592. this.$router.replace(`/chartpanel/${chart.chart_id}`)
  593. this.showMyCharts = false
  594. })
  595. },
  596. deleteChart(chart) {
  597. this.$confirm(this.$t('chart.deleteConfirm', chart.chart_name), this.$t('common.confirm')).then(() => {
  598. deleteChart({ chart_id: chart.chart_id }).then(() => {
  599. // if (this.$route.params.id === chart.chart_id) {
  600. // this.$router.push('/chartpanel/create')
  601. // this.showMyCharts = false
  602. // } else {
  603. // this.viewAllChart()
  604. // }
  605. if (localStorage.getItem('ChartPanelIsEditId') === chart.chart_id) {
  606. this.$router.push('/chartpanel/create')
  607. this.showMyCharts = false
  608. } else {
  609. this.viewAllChart()
  610. }
  611. this.$message({
  612. type: 'success',
  613. message: this.$t('common.deleteSuccess')
  614. })
  615. })
  616. })
  617. },
  618. handleHelp(command) {
  619. if (command === 'guide') {
  620. driver.defineSteps(steps)
  621. driver.start()
  622. }
  623. },
  624. handleDownload() {
  625. import('@/vendor/Export2Excel').then(excel => {
  626. const tHeader = this.allSelected.map(item => item.Column)
  627. const filterVal = tHeader
  628. const data = this.formatJson(filterVal, this.result)
  629. excel.export_json_to_excel({ header: tHeader, data, filename: 'DataExport' + parseTime(Date.now(), '{m}{d}{h}{i}{s}'), autoWidth: true })
  630. })
  631. },
  632. formatJson(filterVal, jsonData) {
  633. return jsonData.map(v =>
  634. filterVal.map(j => {
  635. const tempArr = j.split('.')
  636. if (tempArr.length <= 1) {
  637. return v[j]
  638. } else {
  639. return tempArr.reduce(
  640. (pre, cur) => (pre[cur] ? pre[cur] : '--'),
  641. v
  642. )
  643. }
  644. })
  645. )
  646. }
  647. }
  648. }
  649. </script>
  650. <style lang="scss" scoped>
  651. .back-button {
  652. display: inline-block;
  653. padding-right: 10px;
  654. margin-right: 10px;
  655. border-right: 1px solid #909090;
  656. cursor: pointer;
  657. span {
  658. padding: 5px;
  659. font-size: 14px;
  660. }
  661. }
  662. .analysis-form {
  663. width: 100%;
  664. padding-right: 20px;
  665. /deep/ .el-form-item--mini.el-form-item {
  666. margin-bottom: 10px;
  667. }
  668. /deep/ .el-form-item--mini .el-form-item__label,
  669. .limit-input {
  670. color: #909399;
  671. font-size: 14px;
  672. }
  673. }
  674. .form-wrapper {
  675. display: flex;
  676. }
  677. .chart-form {
  678. width: 250px;
  679. /deep/ .el-form-item--mini.el-form-item {
  680. margin-bottom: 10px;
  681. }
  682. }
  683. .draggable-wrapper {
  684. font-size: 14px;
  685. min-height: 30px;
  686. border-bottom: 1px solid #e4e7ed;
  687. .draggable-item {
  688. margin-right: 10px;
  689. }
  690. /deep/ .el-select--mini {
  691. margin: 0;
  692. }
  693. }
  694. .selected-field {
  695. /deep/ .el-input__inner {
  696. height: 20px;
  697. line-height: 20px;
  698. border: none;
  699. background-color: rgba($color: #fff, $alpha: 0);
  700. padding: 0;
  701. }
  702. /deep/ .el-input__suffix {
  703. right: 0px;
  704. .el-input__suffix-inner {
  705. display: inline-block;
  706. height: 20px;
  707. line-height: 20px;
  708. .el-input__icon {
  709. font-size: 12px;
  710. line-height: 20px;
  711. }
  712. }
  713. }
  714. }
  715. .help-center-wrapper {
  716. cursor: pointer;
  717. position: fixed;
  718. bottom: 25px;
  719. right: 25px;
  720. .help-center {
  721. width: 45px;
  722. height: 45px;
  723. background: #fff;
  724. border-radius: 50%;
  725. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  726. line-height: 45px;
  727. font-size: 20px;
  728. color: #205cd8;
  729. text-align: center;
  730. /deep/ .el-dropdown {
  731. font-size: 20px;
  732. color: #205cd8;
  733. }
  734. }
  735. }
  736. .el-dialog__body {
  737. padding: 20px 20px 50px 20px;
  738. color: #606266;
  739. font-size: 14px;
  740. word-break: break-all;
  741. }
  742. </style>