index.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. <!--
  2. * @Descripttion: 大屏设计器
  3. * @Author: lide1202@hotmail.com
  4. * @Date: 2021-3-13 11:04:24
  5. * @Last Modified by: lide1202@hotmail.com
  6. * @Last Modified time: 2021-3-13 11:04:24
  7. !-->
  8. <template>
  9. <div class="layout">
  10. <div
  11. v-if="toolIsShow"
  12. class="layout-left"
  13. :style="{ width: widthLeftForTools + 'px' }"
  14. >
  15. <el-tabs class="layout-left" type="border-card" :stretch="true">
  16. <!-- 左侧组件栏-->
  17. <el-tab-pane label="工具栏">
  18. <span slot="label"><i class="el-icon-date icon"></i>工具栏</span>
  19. <div class="chart-type">
  20. <el-tabs class="type-left" tab-position="left">
  21. <el-tab-pane
  22. v-for="(item, index) in widgetTools"
  23. :key="index"
  24. :label="item.name"
  25. >
  26. <li
  27. v-for="(it, idx) in item.list"
  28. :key="idx"
  29. draggable="true"
  30. @dragstart="dragStart(it.code)"
  31. @dragend="dragEnd()"
  32. >
  33. <div class="tools-item">
  34. <span class="tools-item-icon">
  35. <i class="iconfont" :class="it.icon"></i>
  36. </span>
  37. <span class="tools-item-text">{{ it.label }}</span>
  38. </div>
  39. </li>
  40. </el-tab-pane>
  41. </el-tabs>
  42. </div>
  43. </el-tab-pane>
  44. <!-- 左侧图层-->
  45. <el-tab-pane label="图层">
  46. <draggable
  47. v-model="layerWidget"
  48. @update="datadragEnd"
  49. :options="{ animation: 300 }"
  50. >
  51. <transition-group>
  52. <div
  53. v-for="(item, index) in layerWidget"
  54. :key="'item' + index"
  55. class="tools-item"
  56. :class="widgetIndex == index ? 'is-active' : ''"
  57. @click="layerClick(index)"
  58. >
  59. <span class="tools-item-icon">
  60. <i class="iconfont" :class="item.icon"></i>
  61. </span>
  62. <span class="tools-item-text">{{ item.label }}</span>
  63. </div>
  64. </transition-group>
  65. </draggable>
  66. </el-tab-pane>
  67. </el-tabs>
  68. </div>
  69. <div
  70. class="layout-left-fold"
  71. :style="{ width: widthLeftForToolsHideButton + 'px' }"
  72. @click="toolIsShow = !toolIsShow"
  73. >
  74. <i class="el-icon-arrow-right" />
  75. </div>
  76. <div
  77. class="layout-middle"
  78. :style="{ width: middleWidth + 'px', height: middleHeight + 'px' }"
  79. >
  80. <div class="top-button">
  81. <span class="btn">
  82. <el-tooltip
  83. class="item"
  84. effect="dark"
  85. content="保存"
  86. placement="bottom"
  87. >
  88. <i class="iconfont iconsave" @click="saveData"></i>
  89. </el-tooltip>
  90. </span>
  91. <span class="btn">
  92. <el-tooltip
  93. class="item"
  94. effect="dark"
  95. content="预览"
  96. placement="bottom"
  97. >
  98. <i class="iconfont iconyulan" @click="viewScreen"></i>
  99. </el-tooltip>
  100. </span>
  101. <span class="btn">
  102. <el-tooltip
  103. class="item"
  104. effect="dark"
  105. content="撤销"
  106. placement="bottom"
  107. >
  108. <i class="iconfont iconundo" @click="handleUndo"></i>
  109. </el-tooltip>
  110. </span>
  111. <span class="btn">
  112. <el-tooltip
  113. class="item"
  114. effect="dark"
  115. content="恢复"
  116. placement="bottom"
  117. >
  118. <i class="iconfont iconhuifubeifen" @click="handleRedo"></i>
  119. </el-tooltip>
  120. </span>
  121. <span class="btn" v-permission="'bigScreenManage:export'">
  122. <el-tooltip
  123. class="item"
  124. effect="dark"
  125. content="导入"
  126. placement="bottom"
  127. >
  128. <el-upload
  129. class="el-upload"
  130. ref="upload"
  131. :action="uploadUrl"
  132. :headers="headers"
  133. accept=".zip"
  134. :on-success="handleUpload"
  135. :on-error="handleError"
  136. :show-file-list="false"
  137. :limit="1"
  138. >
  139. <i class="iconfont icondaoru"></i>
  140. </el-upload>
  141. </el-tooltip>
  142. </span>
  143. <span class="btn border-left" v-permission="'bigScreenManage:import'">
  144. <ul class="nav">
  145. <li>
  146. <i class="iconfont icondaochu"></i
  147. ><i class="el-icon-arrow-down"></i>
  148. <ul>
  149. <li>
  150. <el-tooltip
  151. class="item"
  152. effect="dark"
  153. content="适合当前系统"
  154. placement="right"
  155. >
  156. <div @click="exportDashboard(1)">导出(包含数据集)</div>
  157. </el-tooltip>
  158. </li>
  159. <li>
  160. <el-tooltip
  161. class="item"
  162. effect="dark"
  163. content="适合跨系统"
  164. placement="right"
  165. >
  166. <div @click="exportDashboard(0)">导出(不包含数据集)</div>
  167. </el-tooltip>
  168. </li>
  169. </ul>
  170. </li>
  171. </ul>
  172. </span>
  173. </div>
  174. <div
  175. class="workbench-container"
  176. :style="{
  177. width: bigscreenWidthInWorkbench + 'px',
  178. height: bigscreenHeightInWorkbench + 'px',
  179. }"
  180. @mousedown="handleMouseDown"
  181. >
  182. <vue-ruler-tool
  183. v-model="dashboard.presetLine"
  184. class="vueRuler"
  185. :step-length="50"
  186. :parent="true"
  187. :position="'relative'"
  188. :is-scale-revise="true"
  189. :visible.sync="dashboard.presetLineVisible"
  190. >
  191. <div
  192. id="workbench"
  193. class="workbench"
  194. :style="{
  195. transform: workbenchTransform,
  196. width: bigscreenWidth + 'px',
  197. height: bigscreenHeight + 'px',
  198. 'background-color': dashboard.backgroundColor,
  199. 'background-image': 'url(' + dashboard.backgroundImage + ')',
  200. 'background-position': '0% 0%',
  201. 'background-size': '100% 100%',
  202. 'background-repeat': 'initial',
  203. 'background-attachment': 'initial',
  204. 'background-origin': 'initial',
  205. 'background-clip': 'initial',
  206. }"
  207. @click.self="setOptionsOnClickScreen"
  208. @drop="widgetOnDragged($event)"
  209. @dragover="dragOver($event)"
  210. >
  211. <div v-if="grade" class="bg-grid"></div>
  212. <widget
  213. ref="widgets"
  214. v-for="(widget, index) in widgets"
  215. :key="index"
  216. v-model="widget.value"
  217. :index="index"
  218. :step="step"
  219. :type="widget.type"
  220. :bigscreen="{ bigscreenWidth, bigscreenHeight }"
  221. @onActivated="setOptionsOnClickWidget"
  222. @contextmenu.prevent.native="rightClick($event, index)"
  223. @mousedown.prevent.native="widgetsClick(index)"
  224. @mouseup.prevent.native="widgetsMouseup"
  225. />
  226. </div>
  227. </vue-ruler-tool>
  228. </div>
  229. </div>
  230. <div class="layout-right" :style="{ width: widthLeftForOptions + 'px' }">
  231. <el-tabs v-model="activeName" type="border-card" :stretch="true">
  232. <el-tab-pane
  233. v-if="
  234. isNotNull(widgetOptions.setup) || isNotNull(widgetOptions.collapse)
  235. "
  236. name="first"
  237. label="配置"
  238. >
  239. <dynamicForm
  240. ref="formData"
  241. :options="widgetOptions.setup"
  242. @onChanged="(val) => widgetValueChanged('setup', val)"
  243. />
  244. </el-tab-pane>
  245. <el-tab-pane
  246. v-if="isNotNull(widgetOptions.data)"
  247. name="second"
  248. label="数据"
  249. >
  250. <dynamicForm
  251. ref="formData"
  252. :options="widgetOptions.data"
  253. @onChanged="(val) => widgetValueChanged('data', val)"
  254. />
  255. </el-tab-pane>
  256. <el-tab-pane
  257. v-if="isNotNull(widgetOptions.position)"
  258. name="third"
  259. label="坐标"
  260. >
  261. <dynamicForm
  262. ref="formData"
  263. :options="widgetOptions.position"
  264. @onChanged="(val) => widgetValueChanged('position', val)"
  265. />
  266. </el-tab-pane>
  267. </el-tabs>
  268. </div>
  269. <content-menu
  270. :visible.sync="visibleContentMenu"
  271. :style-obj="styleObj"
  272. @deletelayer="deletelayer"
  273. @copylayer="copylayer"
  274. @istopLayer="istopLayer"
  275. @setlowLayer="setlowLayer"
  276. @moveupLayer="moveupLayer"
  277. @movedownLayer="movedownLayer"
  278. />
  279. </div>
  280. </template>
  281. <script>
  282. import {
  283. insertDashboard,
  284. detailDashboard,
  285. importDashboard,
  286. exportDashboard,
  287. } from "@/api/bigscreen";
  288. import { widgetTools, getToolByCode } from "./tools/index";
  289. import widget from "./widget/widget.vue";
  290. import dynamicForm from "./components/dynamicForm.vue";
  291. import draggable from "vuedraggable";
  292. import VueRulerTool from "vue-ruler-tool"; // 大屏设计页面的标尺插件
  293. import contentMenu from "./components/contentMenu";
  294. import { getToken } from "@/utils/auth";
  295. import { Revoke } from "@/utils/revoke"; //处理历史记录 2022-02-22
  296. export default {
  297. name: "Login",
  298. components: {
  299. draggable,
  300. VueRulerTool,
  301. widget,
  302. dynamicForm,
  303. contentMenu,
  304. },
  305. data() {
  306. return {
  307. uploadUrl:
  308. process.env.BASE_API +
  309. "/reportDashboard/import/" +
  310. this.$route.query.reportCode,
  311. grade: false,
  312. layerWidget: [],
  313. widgetTools: widgetTools, // 左侧工具栏的组件图标,将js变量加入到当前作用域
  314. widthLeftForTools: 200, // 左侧工具栏宽度
  315. widthLeftForToolsHideButton: 15, // 左侧工具栏折叠按钮宽度
  316. widthLeftForOptions: 300, // 右侧属性配置区
  317. widthPaddingTools: 18,
  318. toolIsShow: true, // 左侧工具栏是否显示
  319. bigscreenWidth: 1920, // 大屏设计的大小
  320. bigscreenHeight: 1080,
  321. revoke: null, //处理历史记录 2022-02-22
  322. // 工作台大屏画布,保存到表gaea_report_dashboard中
  323. dashboard: {
  324. id: null,
  325. title: "", // 大屏页面标题
  326. width: 1920, // 大屏设计宽度
  327. height: 1080, // 大屏设计高度
  328. backgroundColor: "", // 大屏背景色
  329. backgroundImage: "", // 大屏背景图片
  330. refreshSeconds: null, // 大屏刷新时间间隔
  331. presetLine: [], // 辅助线
  332. presetLineVisible: true, // 辅助线是否显示
  333. },
  334. // 大屏的标记
  335. screenCode: "",
  336. dragWidgetCode: "", //从工具栏拖拽的组件code
  337. // 大屏画布中的组件
  338. widgets: [
  339. {
  340. // type和value最终存到数据库中去,保存到gaea_report_dashboard_widget中
  341. type: "widget-text",
  342. value: {
  343. setup: {},
  344. data: {},
  345. position: {
  346. width: 100,
  347. height: 100,
  348. left: 0,
  349. top: 0,
  350. zIndex: 0,
  351. },
  352. },
  353. // options属性是从工具栏中拿到的tools中拿到
  354. options: [],
  355. },
  356. ], // 工作区中拖放的组件
  357. // 当前激活组件
  358. widgetIndex: 0,
  359. // 当前激活组件右侧配置属性
  360. widgetOptions: {
  361. setup: [], // 配置
  362. data: [], // 数据
  363. position: [], // 坐标
  364. },
  365. flagWidgetClickStopPropagation: false, // 点击组件时阻止事件冒泡传递到画布click事件上
  366. styleObj: {
  367. left: 0,
  368. top: 0,
  369. },
  370. visibleContentMenu: false,
  371. rightClickIndex: -1,
  372. activeName: "first",
  373. };
  374. },
  375. computed: {
  376. step() {
  377. return Number(100 / (this.bigscreenScaleInWorkbench * 100));
  378. },
  379. headers() {
  380. return {
  381. Authorization: getToken(), // 直接从本地获取token就行
  382. };
  383. },
  384. // 左侧折叠切换时,动态计算中间区的宽度
  385. middleWidth() {
  386. let widthLeftAndRight = 0;
  387. if (this.toolIsShow) {
  388. widthLeftAndRight += this.widthLeftForTools; // 左侧工具栏宽度
  389. }
  390. widthLeftAndRight += this.widthLeftForToolsHideButton; // 左侧工具栏折叠按钮宽度
  391. widthLeftAndRight += this.widthLeftForOptions; // 右侧配置栏宽度
  392. let middleWidth = this.bodyWidth - widthLeftAndRight;
  393. return middleWidth;
  394. },
  395. middleHeight() {
  396. return this.bodyHeight;
  397. },
  398. // 设计台按大屏的缩放比例
  399. bigscreenScaleInWorkbench() {
  400. let widthScale =
  401. (this.middleWidth - this.widthPaddingTools) / this.bigscreenWidth;
  402. let heightScale =
  403. (this.middleHeight - this.widthPaddingTools) / this.bigscreenHeight;
  404. return Math.min(widthScale, heightScale);
  405. },
  406. workbenchTransform() {
  407. return `scale(${this.bigscreenScaleInWorkbench}, ${this.bigscreenScaleInWorkbench})`;
  408. },
  409. // 大屏在设计模式的大小
  410. bigscreenWidthInWorkbench() {
  411. return this.getPXUnderScale(this.bigscreenWidth) + this.widthPaddingTools;
  412. },
  413. bigscreenHeightInWorkbench() {
  414. return (
  415. this.getPXUnderScale(this.bigscreenHeight) + this.widthPaddingTools
  416. );
  417. },
  418. },
  419. watch: {
  420. widgets: {
  421. handler(val) {
  422. this.handlerLayerWidget(val);
  423. //以下部分是记录历史
  424. this.$nextTick(() => {
  425. this.revoke.push(this.widgets);
  426. });
  427. },
  428. deep: true,
  429. },
  430. },
  431. created() {
  432. /* 以下是记录历史的 */
  433. this.revoke = new Revoke();
  434. },
  435. mounted() {
  436. // 如果是新的设计工作台
  437. this.initEchartData();
  438. this.widgets = [];
  439. window.addEventListener("mouseup", () => {
  440. this.grade = false;
  441. });
  442. },
  443. methods: {
  444. /**
  445. * @description: 恢复
  446. * @param {*}
  447. * @return {*}
  448. */
  449. handleUndo() {
  450. const record = this.revoke.undo();
  451. if (!record) {
  452. return false;
  453. }
  454. this.widgets = record;
  455. },
  456. /**
  457. * @description: 重做
  458. * @param {*}
  459. * @return {*}
  460. */
  461. handleRedo() {
  462. const record = this.revoke.redo();
  463. if (!record) {
  464. return false;
  465. }
  466. this.widgets = record;
  467. },
  468. handlerLayerWidget(val) {
  469. const layerWidgetArr = [];
  470. for (let i = 0; i < val.length; i++) {
  471. const obj = {};
  472. obj.icon = getToolByCode(val[i].type).icon;
  473. const options = val[i].options["setup"];
  474. options.forEach((el) => {
  475. if (el.name == "layerName") {
  476. obj.label = el.value;
  477. }
  478. });
  479. layerWidgetArr.push(obj);
  480. }
  481. this.layerWidget = layerWidgetArr;
  482. },
  483. async initEchartData() {
  484. const reportCode = this.$route.query.reportCode;
  485. const { code, data } = await detailDashboard(reportCode);
  486. if (code != 200) return;
  487. const processData = this.handleInitEchartsData(data);
  488. const screenData = this.handleBigScreen(data.dashboard);
  489. this.widgets = processData;
  490. this.dashboard = screenData;
  491. this.bigscreenWidth = this.dashboard.width;
  492. this.bigscreenHeight = this.dashboard.height;
  493. },
  494. handleBigScreen(data) {
  495. const optionScreen = getToolByCode("screen").options;
  496. const setup = optionScreen.setup;
  497. for (const key in data) {
  498. for (let i = 0; i < setup.length; i++) {
  499. if (key == setup[i].name) {
  500. setup[i].value = data[key];
  501. }
  502. }
  503. }
  504. this.setOptionsOnClickScreen();
  505. return {
  506. backgroundColor: (data && data.backgroundColor) || "",
  507. backgroundImage: (data && data.backgroundImage) || "",
  508. height: (data && data.height) || "1080",
  509. title: (data && data.title) || "",
  510. width: (data && data.width) || "1920",
  511. };
  512. },
  513. handleInitEchartsData(data) {
  514. const widgets = data.dashboard ? data.dashboard.widgets : [];
  515. const widgetsData = [];
  516. for (let i = 0; i < widgets.length; i++) {
  517. let obj = {};
  518. obj.type = widgets[i].type;
  519. obj.value = {
  520. setup: widgets[i].value.setup,
  521. data: widgets[i].value.data,
  522. position: widgets[i].value.position,
  523. };
  524. const tool = this.deepClone(getToolByCode(widgets[i].type));
  525. const option = tool.options;
  526. const options = this.handleOptionsData(widgets[i].value, option);
  527. obj.options = options;
  528. widgetsData.push(obj);
  529. }
  530. return widgetsData;
  531. },
  532. handleOptionsData(data, option) {
  533. for (const key in data.setup) {
  534. for (let i = 0; i < option.setup.length; i++) {
  535. let item = option.setup[i];
  536. if (Object.prototype.toString.call(item) == "[object Object]") {
  537. if (key == option.setup[i].name) {
  538. option.setup[i].value = data.setup[key];
  539. }
  540. } else if (Object.prototype.toString.call(item) == "[object Array]") {
  541. for (let j = 0; j < item.length; j++) {
  542. const list = item[j].list;
  543. list.forEach((el) => {
  544. if (key == el.name) {
  545. el.value = data.setup[key];
  546. }
  547. });
  548. }
  549. }
  550. }
  551. }
  552. // position
  553. for (const key in data.position) {
  554. for (let i = 0; i < option.position.length; i++) {
  555. if (key == option.position[i].name) {
  556. option.position[i].value = data.position[key];
  557. }
  558. }
  559. }
  560. // data
  561. for (const key in data.data) {
  562. for (let i = 0; i < option.data.length; i++) {
  563. if (key == option.data[i].name) {
  564. option.data[i].value = data.data[key];
  565. }
  566. }
  567. }
  568. return option;
  569. },
  570. // 保存数据
  571. async saveData() {
  572. if (!this.widgets || this.widgets.length == 0) {
  573. this.$message.error("请添加组件");
  574. return;
  575. }
  576. const screenData = {
  577. reportCode: this.$route.query.reportCode,
  578. dashboard: {
  579. title: this.dashboard.title,
  580. width: this.dashboard.width,
  581. height: this.dashboard.height,
  582. backgroundColor: this.dashboard.backgroundColor,
  583. backgroundImage: this.dashboard.backgroundImage,
  584. },
  585. widgets: this.widgets,
  586. };
  587. const { code, data } = await insertDashboard(screenData);
  588. if (code == "200") {
  589. this.$message.success("保存成功!");
  590. }
  591. },
  592. // 预览
  593. viewScreen() {
  594. let routeUrl = this.$router.resolve({
  595. path: "/bigscreen/viewer",
  596. query: { reportCode: this.$route.query.reportCode },
  597. });
  598. window.open(routeUrl.href, "_blank");
  599. },
  600. // 导出
  601. async exportDashboard(val) {
  602. const fileName = this.$route.query.reportCode + ".zip";
  603. const param = {
  604. reportCode: this.$route.query.reportCode,
  605. showDataSet: val,
  606. };
  607. exportDashboard(param).then((res) => {
  608. const that = this;
  609. const type = res.type;
  610. if (type == "application/json") {
  611. let reader = new FileReader();
  612. reader.readAsText(res, "utf-8");
  613. reader.onload = function () {
  614. const data = JSON.parse(reader.result);
  615. that.$message.error(data.message);
  616. };
  617. return;
  618. }
  619. const blob = new Blob([res], { type: "application/octet-stream" });
  620. if (window.navigator.msSaveOrOpenBlob) {
  621. //msSaveOrOpenBlob方法返回bool值
  622. navigator.msSaveBlob(blob, fileName); //本地保存
  623. } else {
  624. const link = document.createElement("a"); //a标签下载
  625. link.href = window.URL.createObjectURL(blob);
  626. link.download = fileName;
  627. link.click();
  628. window.URL.revokeObjectURL(link.href);
  629. }
  630. });
  631. },
  632. // 上传成功的回调
  633. handleUpload(response, file, fileList) {
  634. //清除el-upload组件中的文件
  635. this.$refs.upload.clearFiles();
  636. //刷新大屏页面
  637. this.initEchartData();
  638. if (response.code == "200") {
  639. this.$message({
  640. message: "导入成功!",
  641. type: "success",
  642. });
  643. } else {
  644. this.$message({
  645. message: response.message,
  646. type: "error",
  647. });
  648. }
  649. },
  650. handleError(err) {
  651. this.$message({
  652. message: "上传失败!",
  653. type: "error",
  654. });
  655. },
  656. // 在缩放模式下的大小
  657. getPXUnderScale(px) {
  658. return this.bigscreenScaleInWorkbench * px;
  659. },
  660. dragStart(widgetCode) {
  661. this.dragWidgetCode = widgetCode;
  662. },
  663. dragEnd() {
  664. this.dragWidgetCode = "";
  665. },
  666. dragOver(evt) {
  667. evt.preventDefault();
  668. evt.stopPropagation();
  669. evt.dataTransfer.dropEffect = "copy";
  670. },
  671. // 拖动一个组件放到工作区中去,在拖动结束时,放到工作区对应的坐标点上去
  672. widgetOnDragged(evt) {
  673. let widgetType = this.dragWidgetCode;
  674. // 获取结束坐标和列名
  675. let eventX = evt.clientX; // 结束在屏幕的x坐标
  676. let eventY = evt.clientY; // 结束在屏幕的y坐标
  677. let workbenchPosition = this.getDomTopLeftById("workbench");
  678. let widgetTopInWorkbench = eventY - workbenchPosition.top;
  679. let widgetLeftInWorkbench = eventX - workbenchPosition.left;
  680. // 计算在缩放模式下的x y
  681. let x = widgetLeftInWorkbench / this.bigscreenScaleInWorkbench;
  682. let y = widgetTopInWorkbench / this.bigscreenScaleInWorkbench;
  683. // 复制一个组件
  684. let tool = getToolByCode(widgetType);
  685. let widgetJson = {
  686. type: widgetType,
  687. value: {
  688. setup: {},
  689. data: {},
  690. position: {
  691. width: 0,
  692. height: 0,
  693. left: 0,
  694. top: 0,
  695. zIndex: 0,
  696. },
  697. },
  698. options: tool.options,
  699. };
  700. // 处理默认值
  701. const widgetJsonValue = this.handleDefaultValue(widgetJson);
  702. //2022年02月22日 修复:可以拖拽放到鼠标的位置
  703. widgetJsonValue.value.position.left =
  704. x - widgetJsonValue.value.position.width / 2;
  705. widgetJsonValue.value.position.top =
  706. y - widgetJsonValue.value.position.height / 2;
  707. // 将选中的复制组件,放到工作区中去
  708. this.widgets.push(this.deepClone(widgetJsonValue));
  709. // 激活新组件的配置属性
  710. this.setOptionsOnClickWidget(this.widgets.length - 1);
  711. },
  712. // 对组件默认值处理
  713. handleDefaultValue(widgetJson) {
  714. for (const key in widgetJson) {
  715. if (key == "options") {
  716. // collapse、data、position、setup
  717. // setup 处理
  718. for (let i = 0; i < widgetJson.options.setup.length; i++) {
  719. const item = widgetJson.options.setup[i];
  720. if (Object.prototype.toString.call(item) == "[object Object]") {
  721. widgetJson.value.setup[item.name] = item.value;
  722. } else if (
  723. Object.prototype.toString.call(item) == "[object Array]"
  724. ) {
  725. for (let j = 0; j < item.length; j++) {
  726. const list = item[j].list;
  727. list.forEach((el) => {
  728. widgetJson.value.setup[el.name] = el.value;
  729. });
  730. }
  731. }
  732. }
  733. // position
  734. for (let i = 0; i < widgetJson.options.position.length; i++) {
  735. const item = widgetJson.options.position[i];
  736. if (item.value) {
  737. widgetJson.value.position[item.name] = item.value;
  738. }
  739. }
  740. // data 处理
  741. if (widgetJson.options.data && widgetJson.options.data.length > 0) {
  742. for (let i = 0; i < widgetJson.options.data.length; i++) {
  743. const item = widgetJson.options.data[i];
  744. if (item.value) {
  745. widgetJson.value.data[item.name] = item.value;
  746. }
  747. }
  748. }
  749. }
  750. }
  751. return widgetJson;
  752. },
  753. layerClick(index) {
  754. this.widgetIndex = index;
  755. this.widgetsClick(index);
  756. },
  757. // 如果是点击大屏设计器中的底层,加载大屏底层属性
  758. setOptionsOnClickScreen() {
  759. this.screenCode = "screen";
  760. // 选中不同的组件 右侧都显示第一栏
  761. this.activeName = "first";
  762. this.widgetOptions = getToolByCode("screen")["options"];
  763. },
  764. // 如果是点击某个组件,获取该组件的配置项
  765. setOptionsOnClickWidget(obj) {
  766. this.screenCode = "";
  767. if (typeof obj == "number") {
  768. this.widgetOptions = this.deepClone(this.widgets[obj]["options"]);
  769. return;
  770. }
  771. if (obj.index < 0 || obj.index >= this.widgets.length) {
  772. return;
  773. }
  774. this.widgetIndex = obj.index;
  775. this.widgets[obj.index].value.position = obj;
  776. this.widgets[obj.index].options.position.forEach((el) => {
  777. for (const key in obj) {
  778. if (el.name == key) {
  779. el.value = obj[key];
  780. }
  781. }
  782. });
  783. this.widgetOptions = this.deepClone(this.widgets[obj.index]["options"]);
  784. },
  785. widgetsClick(index) {
  786. const draggableArr = this.$refs.widgets;
  787. for (let i = 0; i < draggableArr.length; i++) {
  788. if (i == index) {
  789. this.$refs.widgets[i].$refs.draggable.setActive(true);
  790. } else {
  791. this.$refs.widgets[i].$refs.draggable.setActive(false);
  792. }
  793. }
  794. this.setOptionsOnClickWidget(index);
  795. this.grade = true;
  796. },
  797. widgetsMouseup(e) {
  798. this.grade = false;
  799. },
  800. handleMouseDown() {
  801. const draggableArr = this.$refs.widgets;
  802. for (let i = 0; i < draggableArr.length; i++) {
  803. this.$refs.widgets[i].$refs.draggable.setActive(false);
  804. }
  805. },
  806. // 将当前选中的组件,右侧属性值更新
  807. widgetValueChanged(key, val) {
  808. console.log("key", key);
  809. console.log("val", val);
  810. console.log(this.widgetOptions);
  811. if (this.screenCode == "screen") {
  812. let newSetup = new Array();
  813. this.dashboard = this.deepClone(val);
  814. console.log("asd", this.dashboard);
  815. console.log(this.widgetOptions);
  816. if (this.bigscreenWidth != this.dashboard.width) {
  817. this.bigscreenWidth = this.dashboard.width;
  818. }
  819. if (this.bigscreenHeight != this.dashboard.height) {
  820. this.bigscreenHeight = this.dashboard.height;
  821. }
  822. this.widgetOptions.setup.forEach((el) => {
  823. if (el.name == "width") {
  824. el.value = this.bigscreenWidth;
  825. } else if (el.name == "height") {
  826. el.value = this.bigscreenHeight;
  827. } else if (this.dashboard.hasOwn(el.name)) {
  828. el["value"] = this.dashboard[el.name];
  829. }
  830. newSetup.push(el);
  831. });
  832. console.log(newSetup);
  833. this.widgetOptions.setup = newSetup;
  834. } else {
  835. for (let i = 0; i < this.widgets.length; i++) {
  836. if (this.widgetIndex == i) {
  837. this.widgets[i].value[key] = this.deepClone(val);
  838. this.setDefaultValue(this.widgets[i].options[key], val);
  839. }
  840. }
  841. }
  842. },
  843. rightClick(event, index) {
  844. this.rightClickIndex = index;
  845. const left = event.clientX;
  846. const top = event.clientY;
  847. if (left || top) {
  848. this.styleObj = {
  849. left: left + "px",
  850. top: top + "px",
  851. display: "block",
  852. };
  853. }
  854. this.visibleContentMenu = true;
  855. return false;
  856. },
  857. setDefaultValue(options, val) {
  858. for (let i = 0; i < options.length; i++) {
  859. if (Object.prototype.toString.call(options[i]) == "[object Object]") {
  860. for (const k in val) {
  861. if (options[i].name == k) {
  862. options[i].value = val[k];
  863. }
  864. }
  865. } else if (
  866. Object.prototype.toString.call(options[i]) == "[object Array]"
  867. ) {
  868. for (let j = 0; j < options[i].length; j++) {
  869. const list = options[i][j].list;
  870. for (let z = 0; z < list.length; z++) {
  871. for (const k in val) {
  872. if (list[z].name == k) {
  873. list[z].value = val[k];
  874. }
  875. }
  876. }
  877. }
  878. }
  879. }
  880. },
  881. datadragEnd(evt) {
  882. evt.preventDefault();
  883. this.widgets = this.swapArr(this.widgets, evt.oldIndex, evt.newIndex);
  884. },
  885. // 数组 元素互换位置
  886. swapArr(arr, oldIndex, newIndex) {
  887. arr[oldIndex] = arr.splice(newIndex, 1, arr[oldIndex])[0];
  888. return arr;
  889. },
  890. // 删除
  891. deletelayer() {
  892. this.widgets.splice(this.rightClickIndex, 1);
  893. },
  894. // 复制
  895. copylayer() {
  896. const obj = this.deepClone(this.widgets[this.rightClickIndex]);
  897. this.widgets.splice(this.widgets.length, 0, obj);
  898. },
  899. // 置顶
  900. istopLayer() {
  901. if (this.rightClickIndex + 1 < this.widgets.length) {
  902. const temp = this.widgets.splice(this.rightClickIndex, 1)[0];
  903. this.widgets.push(temp);
  904. }
  905. },
  906. // 置底
  907. setlowLayer() {
  908. if (this.rightClickIndex != 0) {
  909. this.widgets.unshift(this.widgets.splice(this.rightClickIndex, 1)[0]);
  910. }
  911. },
  912. // 上移一层
  913. moveupLayer() {
  914. if (this.rightClickIndex != 0) {
  915. this.widgets[this.rightClickIndex] = this.widgets.splice(
  916. this.rightClickIndex - 1,
  917. 1,
  918. this.widgets[this.rightClickIndex]
  919. )[0];
  920. } else {
  921. this.widgets.push(this.widgets.shift());
  922. }
  923. },
  924. // 下移一层
  925. movedownLayer() {
  926. if (this.rightClickIndex != this.widgets.length - 1) {
  927. this.widgets[this.rightClickIndex] = this.widgets.splice(
  928. this.rightClickIndex + 1,
  929. 1,
  930. this.widgets[this.rightClickIndex]
  931. )[0];
  932. } else {
  933. this.widgets.unshift(this.widgets.splice(this.rightClickIndex, 1)[0]);
  934. }
  935. },
  936. },
  937. };
  938. </script>
  939. <style scoped lang="scss">
  940. .mr10 {
  941. margin-right: 10px;
  942. }
  943. .ml20 {
  944. margin-left: 20px;
  945. }
  946. .border-right {
  947. border-right: 1px solid #273b4d;
  948. }
  949. .border-left {
  950. border-left: 1px solid #273b4d;
  951. }
  952. .el-icon-arrow-down {
  953. font-size: 10px;
  954. }
  955. .is-active {
  956. background: #31455d !important;
  957. color: #bfcbd9 !important;
  958. }
  959. .layout {
  960. display: -webkit-box;
  961. display: -ms-flexbox;
  962. display: flex;
  963. width: 100%;
  964. height: 100%;
  965. -webkit-box-sizing: border-box;
  966. box-sizing: border-box;
  967. overflow: hidden;
  968. .layout-left {
  969. display: inline-block;
  970. height: 100%;
  971. box-sizing: border-box;
  972. -webkit-box-sizing: border-box;
  973. border: 0px;
  974. background-color: #263445;
  975. //工具栏一个元素
  976. .tools-item {
  977. display: flex;
  978. position: relative;
  979. width: 100%;
  980. height: 48px;
  981. align-items: center;
  982. -webkit-box-align: center;
  983. padding: 0 6px;
  984. cursor: pointer;
  985. font-size: 12px;
  986. margin-bottom: 1px;
  987. .tools-item-icon {
  988. color: #409eff;
  989. margin-right: 10px;
  990. width: 53px;
  991. height: 30px;
  992. line-height: 30px;
  993. text-align: center;
  994. display: block;
  995. border: 1px solid #3a4659;
  996. background: #282a30;
  997. }
  998. .tools-item-text {
  999. }
  1000. }
  1001. }
  1002. .layout-left-fold {
  1003. display: -webkit-box;
  1004. display: -ms-flexbox;
  1005. display: flex;
  1006. height: 100%;
  1007. font-size: 12px;
  1008. overflow: hidden;
  1009. background-color: #242a30;
  1010. cursor: pointer;
  1011. padding-top: 26%;
  1012. i {
  1013. font-size: 18px;
  1014. width: 18px;
  1015. height: 23px;
  1016. margin-left: 0px;
  1017. color: #bfcbd9;
  1018. }
  1019. }
  1020. .layout-middle {
  1021. // display: flex;
  1022. position: relative;
  1023. //width: calc(100% - 445px);
  1024. height: 100%;
  1025. background-color: rgb(36, 42, 48);
  1026. box-sizing: border-box;
  1027. -webkit-box-sizing: border-box;
  1028. border: 1px solid rgb(36, 42, 48);
  1029. align-items: center;
  1030. vertical-align: middle;
  1031. text-align: center;
  1032. .top-button {
  1033. display: flex;
  1034. flex-direction: row;
  1035. height: 40px;
  1036. line-height: 40px;
  1037. margin-left: 9px;
  1038. .btn {
  1039. color: #788994;
  1040. width: 55px;
  1041. text-align: center;
  1042. display: block;
  1043. cursor: pointer;
  1044. .el-icon-arrow-down {
  1045. transform: rotate(0deg);
  1046. -ms-transform: rotate(0deg); /* IE 9 */
  1047. -moz-transform: rotate(0deg); /* Firefox */
  1048. -webkit-transform: rotate(0deg); /* Safari 和 Chrome */
  1049. -o-transform: rotate(0deg); /* Opera */
  1050. transition: all 0.4s ease-in-out;
  1051. }
  1052. &:hover {
  1053. background: rgb(25, 29, 34);
  1054. .el-icon-arrow-down {
  1055. transform: rotate(180deg);
  1056. -ms-transform: rotate(180deg); /* IE 9 */
  1057. -moz-transform: rotate(180deg); /* Firefox */
  1058. -webkit-transform: rotate(180deg); /* Safari 和 Chrome */
  1059. -o-transform: rotate(180deg); /* Opera */
  1060. transition: all 0.4s ease-in-out;
  1061. }
  1062. }
  1063. }
  1064. }
  1065. .workbench-container {
  1066. position: relative;
  1067. -webkit-transform-origin: 0 0;
  1068. transform-origin: 0 0;
  1069. -webkit-box-sizing: border-box;
  1070. box-sizing: border-box;
  1071. margin: 0;
  1072. padding: 0;
  1073. .vueRuler {
  1074. width: 100%;
  1075. padding: 18px 0px 0px 18px;
  1076. }
  1077. .workbench {
  1078. background-color: #1e1e1e;
  1079. position: relative;
  1080. -webkit-user-select: none;
  1081. -moz-user-select: none;
  1082. -ms-user-select: none;
  1083. user-select: none;
  1084. -webkit-transform-origin: 0 0;
  1085. transform-origin: 0 0;
  1086. margin: 0;
  1087. padding: 0;
  1088. }
  1089. .bg-grid {
  1090. position: absolute;
  1091. top: 0;
  1092. left: 0;
  1093. width: 100%;
  1094. height: 100%;
  1095. background-size: 30px 30px, 30px 30px;
  1096. background-image: linear-gradient(
  1097. hsla(0, 0%, 100%, 0.1) 1px,
  1098. transparent 0
  1099. ),
  1100. linear-gradient(90deg, hsla(0, 0%, 100%, 0.1) 1px, transparent 0);
  1101. // z-index: 2;
  1102. }
  1103. }
  1104. .bottom-text {
  1105. width: 100%;
  1106. color: #a0a0a0;
  1107. font-size: 16px;
  1108. position: absolute;
  1109. bottom: 20px;
  1110. }
  1111. }
  1112. .layout-right {
  1113. display: inline-block;
  1114. height: 100%;
  1115. }
  1116. /deep/ .el-tabs--border-card {
  1117. border: 0;
  1118. .el-tabs__header {
  1119. .el-tabs__nav {
  1120. .el-tabs__item {
  1121. background-color: #242f3b;
  1122. border: 0px;
  1123. }
  1124. .el-tabs__item.is-active {
  1125. background-color: #31455d;
  1126. }
  1127. }
  1128. }
  1129. .el-tabs__content {
  1130. background-color: #242a30;
  1131. height: calc(100vh - 39px);
  1132. overflow-x: hidden;
  1133. overflow-y: auto;
  1134. .el-tab-pane {
  1135. color: #bfcbd9;
  1136. }
  1137. &::-webkit-scrollbar {
  1138. width: 5px;
  1139. height: 14px;
  1140. }
  1141. &::-webkit-scrollbar-track,
  1142. &::-webkit-scrollbar-thumb {
  1143. border-radius: 1px;
  1144. border: 0 solid transparent;
  1145. }
  1146. &::-webkit-scrollbar-track-piece {
  1147. /*修改滚动条的背景和圆角*/
  1148. background: #29405c;
  1149. -webkit-border-radius: 7px;
  1150. }
  1151. &::-webkit-scrollbar-track {
  1152. box-shadow: 1px 1px 5px rgba(116, 148, 170, 0.5) inset;
  1153. }
  1154. &::-webkit-scrollbar-thumb {
  1155. min-height: 20px;
  1156. background-clip: content-box;
  1157. box-shadow: 0 0 0 5px rgba(116, 148, 170, 0.5) inset;
  1158. }
  1159. &::-webkit-scrollbar-corner {
  1160. background: transparent;
  1161. }
  1162. /*修改垂直滚动条的样式*/
  1163. &::-webkit-scrollbar-thumb:vertical {
  1164. background-color: #00113a;
  1165. -webkit-border-radius: 7px;
  1166. }
  1167. /*修改水平滚动条的样式*/
  1168. &::-webkit-scrollbar-thumb:horizontal {
  1169. background-color: #00113a;
  1170. -webkit-border-radius: 7px;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. ul,
  1176. li {
  1177. list-style: none;
  1178. margin: 0;
  1179. padding: 0;
  1180. }
  1181. .nav {
  1182. width: 40px;
  1183. padding: 0;
  1184. list-style: none;
  1185. /* overflow: hidden; */
  1186. }
  1187. .nav {
  1188. zoom: 1;
  1189. }
  1190. .nav:before,
  1191. .nav:after {
  1192. content: "";
  1193. display: table;
  1194. }
  1195. .nav:after {
  1196. clear: both;
  1197. }
  1198. .nav > li {
  1199. width: 55px;
  1200. text-align: left;
  1201. position: relative;
  1202. }
  1203. .nav > li a {
  1204. float: left;
  1205. padding: 12px 30px;
  1206. color: #999;
  1207. font: bold 12px;
  1208. text-decoration: none;
  1209. }
  1210. .nav > li:hover {
  1211. color: #788994;
  1212. }
  1213. .nav > li ul {
  1214. visibility: hidden;
  1215. position: absolute;
  1216. z-index: 1000;
  1217. list-style: none;
  1218. left: 0;
  1219. padding: 0;
  1220. background-color: rgb(36, 42, 48);
  1221. opacity: 0;
  1222. _margin: 0;
  1223. width: 120px;
  1224. transition: all 0.2s ease-in-out;
  1225. }
  1226. .nav > li:hover > ul {
  1227. opacity: 1;
  1228. visibility: visible;
  1229. margin: 0;
  1230. li:hover {
  1231. background-color: rgb(25, 29, 34);
  1232. }
  1233. }
  1234. .nav ul li {
  1235. float: left;
  1236. display: block;
  1237. border: 0;
  1238. width: 100%;
  1239. font-size: 12px;
  1240. }
  1241. .nav ul a {
  1242. padding: 10px;
  1243. width: 100%;
  1244. display: block;
  1245. float: none;
  1246. height: 120px;
  1247. border: 1px solid #30445c;
  1248. background-color: rgb(25, 29, 34);
  1249. transition: all 0.2s ease-in-out;
  1250. }
  1251. .nav ul a:hover {
  1252. border: 1px solid #3c5e88;
  1253. }
  1254. .nav ul li:first-child > a:hover:before {
  1255. border-bottom-color: #04acec;
  1256. }
  1257. .nav ul ul {
  1258. top: 0;
  1259. left: 120px;
  1260. width: 400px;
  1261. height: 300px;
  1262. overflow: auto;
  1263. padding: 10px;
  1264. _margin: 0;
  1265. }
  1266. .nav ul ul li {
  1267. width: 120px;
  1268. height: 120px;
  1269. margin-right: 3px;
  1270. display: block;
  1271. float: left;
  1272. }
  1273. .nav .item {
  1274. padding: 5px;
  1275. }
  1276. /deep/ .vue-ruler-h {
  1277. opacity: 0.3;
  1278. }
  1279. /deep/ .vue-ruler-v {
  1280. opacity: 0.3;
  1281. }
  1282. .layout-left {
  1283. width: 200px;
  1284. background: #242a30;
  1285. overflow-x: hidden;
  1286. overflow-y: auto;
  1287. .chart-type {
  1288. display: flex;
  1289. flex-direction: row;
  1290. overflow: hidden;
  1291. .type-left {
  1292. width: 100%;
  1293. height: calc(100vh - 80px);
  1294. text-align: center;
  1295. /deep/.el-tabs__header {
  1296. width: 30%;
  1297. margin-right: 0;
  1298. .el-tabs__nav-wrap {
  1299. &::after {
  1300. background: transparent;
  1301. }
  1302. .el-tabs__item {
  1303. text-align: center;
  1304. width: 100% !important;
  1305. color: #fff;
  1306. padding: 0;
  1307. font-size: 12px !important;
  1308. }
  1309. }
  1310. }
  1311. /deep/.el-tabs__content {
  1312. width: 70%;
  1313. }
  1314. }
  1315. }
  1316. //工具栏一个元素
  1317. .tools-item {
  1318. display: flex;
  1319. position: relative;
  1320. width: 100%;
  1321. height: 48px;
  1322. align-items: center;
  1323. -webkit-box-align: center;
  1324. padding: 0 6px;
  1325. cursor: pointer;
  1326. font-size: 12px;
  1327. margin-bottom: 1px;
  1328. .tools-item-icon {
  1329. color: #409eff;
  1330. margin-right: 10px;
  1331. width: 53px;
  1332. height: 30px;
  1333. line-height: 30px;
  1334. text-align: center;
  1335. display: block;
  1336. border: 1px solid #3a4659;
  1337. background: #282a30;
  1338. }
  1339. .tools-item-text {
  1340. font-size: 12px !important;
  1341. }
  1342. }
  1343. /deep/.el-tabs__content {
  1344. padding: 0;
  1345. }
  1346. }
  1347. /* 设置滚动条的样式 */
  1348. ::-webkit-scrollbar {
  1349. width: 0;
  1350. }
  1351. /* 滚动槽 */
  1352. ::-webkit-scrollbar-track {
  1353. -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.3);
  1354. }
  1355. /* 滚动条滑块 */
  1356. ::-webkit-scrollbar-thumb {
  1357. background: rgba(0, 0, 0, 0.1);
  1358. -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5);
  1359. }
  1360. ::-webkit-scrollbar-thumb:window-inactive {
  1361. background: rgba(255, 0, 0, 0.4);
  1362. }
  1363. </style>