60b9fa67cb353ff534ddd1d34f885d867999c8b0.svn-base 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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'" class="save" style="float: right;margin:0 10px 0 0;" :disabled="LastInsertId == ''" @click="handleLinkDB">添加到仪表盘</el-button>
  17. <el-button v-if="this.$route.params.isEdit == 'edit'" class="save" 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" :is-edit="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;" :max="60000" @blur="editLimit=false" />
  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 v-if="sonRefresh" id="vizPanel" v-loading="loading" :data="result" :chart-type.sync="chartType" :schema="allSelected" />
  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. console.log('sqlSentencethis.filterStr', this.filterStr)
  203. }
  204. },
  205. watch: {
  206. sqlSentence(value) {
  207. if (value) {
  208. this.fetchData(value)
  209. } else {
  210. this.result = []
  211. }
  212. },
  213. '$route.params.id': {
  214. immediate: true,
  215. handler() {
  216. console.log('this.$route.params.id=====================', this.$route.params.id)
  217. if (this.$route.params.id !== 'create') {
  218. console.log('我是编辑图表哦~~~')
  219. console.log('this.$route.params.id', this.$route.params.id)
  220. console.log('localStorage==========', localStorage.getItem('ChartPanelIsEditId'))
  221. console.log('this.$store.state.user.dashchartid==========', this.$store.state.user.dashchartid)
  222. if (this.$route.params.id) {
  223. console.log('我是编辑图表第一次跳转~~~')
  224. var send_data = {
  225. name: 'getChartDetail',
  226. parammaps: {
  227. pastureid: Cookies.get('pastureid'),
  228. id: this.$route.params.id
  229. }
  230. }
  231. GetDataByName(send_data).then(response => {
  232. console.log('图表数据', response.data.list)
  233. const chart = response.data.list[0]
  234. this.chartName = chart.chart_name
  235. this.chartDesc = chart.desc
  236. const content = JSON.parse(chart.content) || {}
  237. this.dataSrc.table = content.dataSrc
  238. this.dataSrc.source_id = chart.source_id
  239. this.chartType = content.chartType
  240. this.limit = content.limit || 200
  241. this.currentFilters = content.filters
  242. this.orderByStrs = content.orderByStrs
  243. store.setCaculColsAction(content.selectedCalcul)
  244. store.setCaculColsAction2(content.selectedCalcul2)
  245. store.setDimensionsAction(content.selectedDimension)
  246. this.$refs.dataPanel.initWithDataSrc(this.dataSrc)
  247. })
  248. } else {
  249. console.log('我是编辑图表切换跳转~~~')
  250. var send_data = {
  251. name: 'getChartDetail',
  252. parammaps: {
  253. pastureid: Cookies.get('pastureid'),
  254. // id: this.$route.params.id
  255. id: localStorage.getItem('ChartPanelIsEditId')
  256. }
  257. }
  258. GetDataByName(send_data).then(response => {
  259. console.log('图表数据', response.data.list)
  260. const chart = response.data.list[0]
  261. this.chartName = chart.chart_name
  262. this.chartDesc = chart.desc
  263. const content = JSON.parse(chart.content) || {}
  264. this.dataSrc.table = content.dataSrc
  265. this.dataSrc.source_id = chart.source_id
  266. this.chartType = content.chartType
  267. this.limit = content.limit || 200
  268. this.currentFilters = content.filters
  269. this.orderByStrs = content.orderByStrs
  270. store.setCaculColsAction(content.selectedCalcul)
  271. store.setCaculColsAction2(content.selectedCalcul2)
  272. store.setDimensionsAction(content.selectedDimension)
  273. this.$refs.dataPanel.initWithDataSrc(this.dataSrc)
  274. })
  275. }
  276. } else {
  277. console.log('我是新增图标哦~~~')
  278. this.chartName = undefined
  279. this.chartDesc = undefined
  280. store.setCaculColsAction([])
  281. store.setCaculColsAction2([])
  282. store.setDimensionsAction([])
  283. this.$nextTick(() => {
  284. this.$refs.dataPanel.initWithDataSrc()
  285. })
  286. }
  287. }
  288. }
  289. },
  290. created() {
  291. },
  292. methods: {
  293. // fetchData(sqlSentence) {
  294. // if (this.loading) {
  295. // this.execInstance && this.execInstance.cancel()
  296. // }
  297. // this.loading = true
  298. // this.execInstance = exeSql()
  299. // this.execInstance.fetch({ source_id: this.dataSrc.source_id, sql: sqlSentence }).then(resp => {
  300. // this.loading = false
  301. // this.result = resp.data
  302. // })
  303. // },
  304. fetchData(sqlSentence) {
  305. if (this.loading) {
  306. this.execInstance && this.execInstance.cancel()
  307. }
  308. this.loading = true
  309. this.execInstance = exeSql()
  310. this.sharedState.caculCols2.map(function(i) {
  311. return (i.is_second = true)
  312. })
  313. console.log('this.currentFilters', this.currentFilters)
  314. const obj = {
  315. dataSrc: this.dataSrc.table,
  316. source_id: this.dataSrc.source_id,
  317. orderByStrs: this.orderByStrs,
  318. limit: this.limit,
  319. selectedCalcul: this.sharedState.caculCols,
  320. selectedCalcul2: this.sharedState.caculCols2,
  321. selectedDimension: this.sharedState.dimensions,
  322. chartType: this.chartType,
  323. filters: this.currentFilters
  324. }
  325. var send_data = { source_id: this.dataSrc.source_id, content: obj, pastureid: Cookies.get('pastureid') }
  326. ExeSqlJiade(send_data).then(response => {
  327. console.log('ExeSql发的数据======', send_data)
  328. console.log('图的数据', response.data.list)
  329. if (response.data !== null) {
  330. console.log('维度+数值获得的数据', Array.isArray(response.data))
  331. // 判断是不是数组!result无论有没有值都必须是数组格式,不然会报错!
  332. if (Array.isArray(response.data)) {
  333. this.loading = false
  334. this.result = response.data
  335. } else {
  336. this.loading = false
  337. this.result = []
  338. }
  339. } else {
  340. this.loading = false
  341. this.result = []
  342. }
  343. })
  344. },
  345. handleDataSrcChange(value) {
  346. console.log('dataSrc======================', value)
  347. this.dataSrc = value
  348. store.setCaculColsAction([])
  349. store.setCaculColsAction2([])
  350. store.setDimensionsAction([])
  351. this.filterStr = undefined
  352. this.orderByStrs = []
  353. },
  354. handleColChange(evt) {
  355. if (evt.added) {
  356. store.addCaculColAction(evt.added.element)
  357. }
  358. },
  359. handleColChange2(evt) {
  360. if (evt.added) {
  361. store.addCaculColAction2(evt.added.element)
  362. }
  363. },
  364. // handleDimensionChange(evt) {
  365. // console.log('handleDimensionChange的evt', evt)
  366. // if (evt.added) {
  367. // store.addDimensionAction(evt.added.element)
  368. // }
  369. // },
  370. handleDimensionChange(evt) {
  371. console.log('this.sharedState.dimensions', this.sharedState.dimensions)
  372. if (evt.added) {
  373. store.addDimensionAction(evt.added.element)
  374. }
  375. if (evt.moved) {
  376. this.sonRefresh = false
  377. this.$nextTick(() => {
  378. this.sonRefresh = true
  379. })
  380. }
  381. },
  382. handleCloseColTag(col) {
  383. store.deleteCaculColAction(col)
  384. },
  385. handleCloseColTag2(col) {
  386. store.deleteCaculColAction2(col)
  387. },
  388. handleCloseDimensionTag(col) {
  389. store.deleteDimensionAction(col)
  390. },
  391. handleAddFilter(value) {
  392. console.log('handleAddFilter', value)
  393. this.filterStr = value
  394. console.log('filterStr', this.filterStr)
  395. },
  396. // 保存
  397. // handleSave() {
  398. // if (!this.chartName) {
  399. // this.$message({
  400. // type: 'warning',
  401. // message: this.$t('chart.chartNameWarning')
  402. // })
  403. // return
  404. // }
  405. // const chartId = this.$route.params.id === 'create' ? undefined : this.$route.params.id
  406. // const obj = {
  407. // dataSrc: this.dataSrc.table,
  408. // source_id: this.dataSrc.source_id,
  409. // orderByStrs: this.orderByStrs,
  410. // limit: this.limit,
  411. // selectedCalcul: this.sharedState.caculCols,
  412. // selectedDimension: this.sharedState.dimensions,
  413. // chartType: this.chartType,
  414. // filters: this.currentFilters
  415. // }
  416. // const data = {
  417. // id: chartId,
  418. // chart_name: this.chartName,
  419. // source_id: this.dataSrc.source_id,
  420. // desc: this.chartDesc,
  421. // content: obj
  422. // }
  423. // if (chartId) {
  424. // updateChart(data).then(resp => {
  425. // this.$message({
  426. // type: 'success',
  427. // message: this.$t('common.saveSuccess')
  428. // })
  429. // })
  430. // } else {
  431. // createChart(data).then(resp => {
  432. // // console.log(resp)
  433. // this.$router.replace(`/chartpanel/${resp.data.id}`)
  434. // this.$message({
  435. // type: 'success',
  436. // message: this.$t('common.saveSuccess')
  437. // })
  438. // })
  439. // }
  440. // },
  441. handleSave() {
  442. if (!this.chartName) {
  443. this.$message({
  444. type: 'warning',
  445. message: this.$t('chart.chartNameWarning')
  446. })
  447. return
  448. }
  449. // const chartId = this.$route.params.id === 'create' ? undefined : this.$route.params.id
  450. const chartId = localStorage.getItem('ChartPanelIsEditId') === 'create' ? undefined : localStorage.getItem('ChartPanelIsEditId')
  451. const obj = {
  452. dataSrc: this.dataSrc.table,
  453. source_id: this.dataSrc.source_id,
  454. orderByStrs: this.orderByStrs,
  455. limit: this.limit,
  456. selectedCalcul: this.sharedState.caculCols,
  457. selectedCalcul2: this.sharedState.caculCols2,
  458. selectedDimension: this.sharedState.dimensions,
  459. chartType: this.chartType,
  460. filters: this.currentFilters
  461. }
  462. const data = {
  463. name: 'insertChart',
  464. parammaps: {
  465. id: chartId,
  466. cname: this.chartName,
  467. source_id: this.dataSrc.source_id,
  468. desc: this.chartDesc,
  469. display: this.chartDesc,
  470. pastureid: Cookies.get('pastureid'),
  471. empid: Cookies.get('employeid'),
  472. emp: Cookies.get('employename'),
  473. content: obj
  474. }
  475. }
  476. var send_data2 = {
  477. name: 'updateChartV2',
  478. parammaps: {
  479. id: chartId,
  480. cname: this.chartName,
  481. source_id: this.dataSrc.source_id,
  482. desc: this.chartDesc,
  483. display: this.chartDesc,
  484. pastureid: Cookies.get('pastureid'),
  485. empid: Cookies.get('employeid'),
  486. emp: Cookies.get('employename'),
  487. content: obj
  488. }
  489. }
  490. this.isSaving = true
  491. if (chartId) {
  492. PostDataByName(send_data2).then(res => {
  493. console.log('编辑保存发送参数', data)
  494. if (res.msg == 'ok') {
  495. this.$message({
  496. type: 'success',
  497. message: this.$t('common.saveSuccess')
  498. })
  499. } else {
  500. this.$message({ type: 'error', message: '保存失败,请不要输入已有的图表名称!' })
  501. }
  502. })
  503. } else {
  504. PostDataByName(data).then(res => {
  505. console.log('新增保存发送参数', data)
  506. if (res.msg == 'ok') {
  507. this.$message({
  508. type: 'success',
  509. message: this.$t('common.saveSuccess')
  510. })
  511. this.LastInsertId = res.data.LastInsertId
  512. } else {
  513. this.$message({ type: 'error', message: '保存失败,请不要输入已有的图表名称!' })
  514. }
  515. })
  516. // createChart(data).then(resp => {
  517. // // console.log(resp)
  518. // this.$router.replace(`/chartpanel/${resp.data.id}`)
  519. // this.$message({
  520. // type: 'success',
  521. // message: this.$t('common.saveSuccess')
  522. // })
  523. // })
  524. }
  525. },
  526. handleLinkDB() {
  527. this.showDashboards = true
  528. var send_data = {
  529. name: 'getdashboards',
  530. parammaps: {
  531. pastureid: Cookies.get('pastureid'),
  532. empid: Cookies.get('employeid'),
  533. emp: Cookies.get('employename')
  534. }
  535. }
  536. dashboardListJiade(send_data).then(resp => {
  537. console.log('看板列表数据:', resp)
  538. this.dashboardList = resp.data.list
  539. })
  540. },
  541. getDbByChart(id) {
  542. dbByChart(id).then(resp => {
  543. this.linkedDbIds = resp.data || []
  544. })
  545. },
  546. isDbDisbaled(db) {
  547. return !!this.linkedDbIds.find(id => id === db.objectId)
  548. },
  549. linkDb() {
  550. if (this.selectedDb == undefined) {
  551. this.$message({ type: 'error', message: '请选择仪表盘' })
  552. return false
  553. }
  554. this.showDashboards = false
  555. console.log(this.$route.params.id)
  556. console.log('仪表盘列表ID:', this.selectedDb)
  557. // var chartid1 = this.$route.params.id
  558. // if (chartid1 == "create") {
  559. // chartid1 = this.LastInsertId
  560. // } else {
  561. // chartid1 = this.$route.params.id // }
  562. var chartid1 = localStorage.getItem('ChartPanelIsEditId')
  563. if (chartid1 == 'create') {
  564. chartid1 = this.LastInsertId
  565. } else {
  566. chartid1 = localStorage.getItem('ChartPanelIsEditId')
  567. }
  568. // var chartid1 = localStorage.getItem('ChartPanelIsEditId')
  569. // if (chartid1 == "create") {
  570. // chartid1 = this.LastInsertId
  571. // } else {
  572. // chartid1 = localStorage.getItem('ChartPanelIsEditId')
  573. // }
  574. const data = {
  575. name: 'insertdashboard_chart',
  576. parammaps: {
  577. did: this.selectedDb,
  578. cid: chartid1,
  579. pastureid: Cookies.get('pastureid')
  580. }
  581. }
  582. PostDataByName(data).then(response => {
  583. if (response.msg == 'ok') {
  584. this.$message({
  585. type: 'success',
  586. message: this.$t('common.saveSuccess')
  587. })
  588. } else {
  589. this.$message({ type: 'error', message: '保存失败111' })
  590. }
  591. })
  592. },
  593. viewAllChart() {
  594. this.showMyCharts = true
  595. // chartList().then(resp => {
  596. // this.myChartList = resp.data
  597. // })
  598. 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' }]
  599. },
  600. switchChart(chart) {
  601. this.$confirm(this.$t('chart.beforeLeaveConfirm'), this.$t('common.confirm')).then(() => {
  602. this.$router.replace(`/chartpanel/${chart.chart_id}`)
  603. this.showMyCharts = false
  604. })
  605. },
  606. deleteChart(chart) {
  607. this.$confirm(this.$t('chart.deleteConfirm', chart.chart_name), this.$t('common.confirm')).then(() => {
  608. deleteChart({ chart_id: chart.chart_id }).then(() => {
  609. // if (this.$route.params.id === chart.chart_id) {
  610. // this.$router.push('/chartpanel/create')
  611. // this.showMyCharts = false
  612. // } else {
  613. // this.viewAllChart()
  614. // }
  615. if (localStorage.getItem('ChartPanelIsEditId') === chart.chart_id) {
  616. this.$router.push('/chartpanel/create')
  617. this.showMyCharts = false
  618. } else {
  619. this.viewAllChart()
  620. }
  621. this.$message({
  622. type: 'success',
  623. message: this.$t('common.deleteSuccess')
  624. })
  625. })
  626. })
  627. },
  628. handleHelp(command) {
  629. if (command === 'guide') {
  630. driver.defineSteps(steps)
  631. driver.start()
  632. }
  633. },
  634. handleDownload() {
  635. import('@/vendor/Export2Excel').then(excel => {
  636. const tHeader = this.allSelected.map(item => item.Column)
  637. const filterVal = tHeader
  638. const data = this.formatJson(filterVal, this.result)
  639. excel.export_json_to_excel({ header: tHeader, data, filename: 'DataExport' + parseTime(Date.now(), '{m}{d}{h}{i}{s}'), autoWidth: true })
  640. })
  641. },
  642. formatJson(filterVal, jsonData) {
  643. return jsonData.map(v =>
  644. filterVal.map(j => {
  645. const tempArr = j.split('.')
  646. if (tempArr.length <= 1) {
  647. return v[j]
  648. } else {
  649. return tempArr.reduce(
  650. (pre, cur) => (pre[cur] ? pre[cur] : '--'),
  651. v
  652. )
  653. }
  654. })
  655. )
  656. }
  657. }
  658. }
  659. </script>
  660. <style lang="scss" scoped>
  661. .back-button {
  662. display: inline-block;
  663. padding-right: 10px;
  664. margin-right: 10px;
  665. border-right: 1px solid #909090;
  666. cursor: pointer;
  667. span {
  668. padding: 5px;
  669. font-size: 14px;
  670. }
  671. }
  672. .analysis-form {
  673. width: 100%;
  674. padding-right: 20px;
  675. /deep/ .el-form-item--mini.el-form-item {
  676. margin-bottom: 10px;
  677. }
  678. /deep/ .el-form-item--mini .el-form-item__label,
  679. .limit-input {
  680. color: #909399;
  681. font-size: 14px;
  682. }
  683. }
  684. .form-wrapper {
  685. display: flex;
  686. }
  687. .chart-form {
  688. width: 250px;
  689. /deep/ .el-form-item--mini.el-form-item {
  690. margin-bottom: 10px;
  691. }
  692. }
  693. .draggable-wrapper {
  694. font-size: 14px;
  695. min-height: 30px;
  696. border-bottom: 1px solid #e4e7ed;
  697. .draggable-item {
  698. margin-right: 10px;
  699. }
  700. /deep/ .el-select--mini {
  701. margin: 0;
  702. }
  703. }
  704. .selected-field {
  705. /deep/ .el-input__inner {
  706. height: 20px;
  707. line-height: 20px;
  708. border: none;
  709. background-color: rgba($color: #fff, $alpha: 0);
  710. padding: 0;
  711. }
  712. /deep/ .el-input__suffix {
  713. right: 0px;
  714. .el-input__suffix-inner {
  715. display: inline-block;
  716. height: 20px;
  717. line-height: 20px;
  718. .el-input__icon {
  719. font-size: 12px;
  720. line-height: 20px;
  721. }
  722. }
  723. }
  724. }
  725. .help-center-wrapper {
  726. cursor: pointer;
  727. position: fixed;
  728. bottom: 25px;
  729. right: 25px;
  730. .help-center {
  731. width: 45px;
  732. height: 45px;
  733. background: #fff;
  734. border-radius: 50%;
  735. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  736. line-height: 45px;
  737. font-size: 20px;
  738. color: #205cd8;
  739. text-align: center;
  740. /deep/ .el-dropdown {
  741. font-size: 20px;
  742. color: #205cd8;
  743. }
  744. }
  745. }
  746. .el-dialog__body {
  747. padding: 20px 20px 50px 20px;
  748. color: #606266;
  749. font-size: 14px;
  750. word-break: break-all;
  751. }
  752. </style>