4ea0302e3e798b93539d85fd53fa5d397ebe32c9.svn-base 30 KB

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