LayoutLeft.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div class="layout-left">
  3. <div class="tabs-container">
  4. <ul class="nav nav-tabs">
  5. <li :class="isActive('data-tab-1')"><a data-toggle="tab" @click="switchTabs('data-tab-1')" idx="0" aria-expanded="true">组件</a>
  6. </li>
  7. <li :class="isActive('data-tab-2')"><a data-toggle="tab" @click="switchTabs('data-tab-2')" idx="1" aria-expanded="false">立方体</a>
  8. </li>
  9. <li :class="isActive('data-tab-3')"><a data-toggle="tab" @click="switchTabs('data-tab-3')" idx="2" aria-expanded="false">数据表</a>
  10. </li>
  11. </ul>
  12. </div>
  13. <div class="tab-content tab-content2">
  14. <div id="data-tab-1" class="tab-pane" :class="isActive('data-tab-1')">
  15. <div class="panel-body" style="padding:0px;overflow:auto;">
  16. <div id="paramtree">a</div>
  17. <div id="comptree"></div>
  18. </div>
  19. </div>
  20. <div id="data-tab-2" class="tab-pane" :class="isActive('data-tab-2')">
  21. <div class="panel-body" style="padding:0px;overflow:auto;">
  22. <div id="datasettree"></div>
  23. </div>
  24. </div>
  25. <div id="data-tab-3" class="tab-pane" :class="isActive('data-tab-3')">
  26. <div class="panel-body" style="padding:0px;overflow:auto;">
  27. <div id="tabletree"></div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import {baseUrl, ajax} from '@/common/biConfig'
  35. import $ from 'jquery'
  36. import "jstree";
  37. import "jstree/dist/themes/default/style.min.css";
  38. export default {
  39. components:{
  40. },
  41. props:{
  42. pageInfo:{
  43. type:Object,
  44. required:true,
  45. default:{}
  46. }
  47. },
  48. data(){
  49. return {
  50. tabActive:"data-tab-1"
  51. }
  52. },
  53. mounted(){
  54. this.initcubes();
  55. this.initdset();
  56. this.regCompAndParamTree();
  57. },
  58. computed: {
  59. },
  60. methods: {
  61. switchTabs(val){
  62. this.tabActive = val;
  63. },
  64. isActive(p){
  65. return this.tabActive === p ? "active" : ""
  66. },
  67. regCompAndParamTree(){
  68. let ts = this;
  69. var dt = [{id:'params', text:'参数', icon:"fa fa-binoculars",state:{opened:true}, children:[
  70. {id:"input", text:"输入框",li_attr:{tp:"param",ptp:"text"},icon:"fa fa-tag comp_color"},
  71. {id:"radio", text:"单选框",li_attr:{tp:"param", ptp:"radio"},icon:"fa fa-tag comp_color"},
  72. {id:"checkbox", text:"多选框",li_attr:{tp:"param",ptp:"checkbox"},icon:"fa fa-tag comp_color"},
  73. {id:"dateselect", text:"日历框",li_attr:{tp:"param", ptp:"dateselect"},icon:"fa fa-tag comp_color"},
  74. {id:"monthselect", text:"月份框",li_attr:{tp:"param", ptp:"monthselect"},icon:"fa fa-tag comp_color"},
  75. {id:"yearselect", text:"年份框",li_attr:{tp:"param", ptp:"yearselect"},icon:"fa fa-tag comp_color"}
  76. ]}
  77. ];
  78. var compDt = [{id:"text", text:"文本",li_attr:{tp:"comp"},icon:"fa fa-file-text-o"},
  79. {id:"box", text:"数据块",li_attr:{tp:"comp"},icon:"fa fa-inbox"},
  80. {id:"chart", text:"图表",li_attr:{tp:"comp"},icon:"fa fa-line-chart"},
  81. {id:"grid", text:"表格",li_attr:{tp:"comp"},icon:"fa fa-table"},
  82. {id:"table", text:"交叉表",li_attr:{tp:"comp"},icon:"fa fa-list-alt"}];
  83. var dragfunc = function(treeDiv){
  84. $("#"+treeDiv+" .jstree-node").draggable({
  85. cursor: "point",
  86. appendTo: "body",
  87. revert: 'invalid',
  88. revertDuration: 250,
  89. cursorAt: { top: 0, left: 'comptree' == treeDiv ? -10 :-35 },
  90. helper:function(e){
  91. var id = $(this).find("a.jstree-anchor:first").text();
  92. return "<div class=\"vakata-dnd\"><span class=\"miconcancel glyphicon glyphicon-remove\"></span>"+id+"</div>";
  93. },
  94. start:function(e){
  95. var ref = $('#'+treeDiv).jstree(true),node = ref.get_node(this);
  96. if(node.id == 'params'){
  97. return false;
  98. }
  99. if(node.li_attr.tp == 'comp'){
  100. //resetWindows('min');
  101. }
  102. return true;
  103. },
  104. stop:function(e){
  105. var ref = $('#'+treeDiv).jstree(true),node = ref.get_node(this);
  106. if(node.li_attr.tp == 'comp'){
  107. //resetWindows('max');
  108. }
  109. $(".indicator").hide();
  110. }
  111. });
  112. }
  113. $('#paramtree').jstree({
  114. core:{
  115. data:dt
  116. },
  117. "plugins" : [
  118. "wholerow"
  119. ]
  120. }).bind("ready.jstree",function(a, b){
  121. dragfunc('paramtree');
  122. }).bind("after_open.jstree", function(){
  123. dragfunc('paramtree');
  124. });
  125. $('#comptree').jstree({
  126. core:{
  127. data:compDt
  128. },
  129. "plugins" : [
  130. "wholerow"
  131. ]
  132. }).bind("ready.jstree",function(a, b){
  133. dragfunc('comptree');
  134. })
  135. //参数接收
  136. $("#optparam").droppable({
  137. accept:"#paramtree .jstree-node",
  138. tolerance:"pointer",
  139. over:function(e, ui){
  140. var ref = $("#paramtree").jstree(true);
  141. var node = ref.get_node(ui.draggable[0]);
  142. var tp = node.li_attr.tp;
  143. if(tp == "param"){
  144. $("#optparam").css("border", "1px solid #ff0000");
  145. $(ui.helper[0]).find("span").removeClass("glyphicon-remove").addClass("glyphicon-ok");
  146. }
  147. },
  148. out:function(e, ui){
  149. $("#optparam").css("border", "1px solid #d3d3d3");
  150. $(ui.helper[0]).find("span").removeClass("glyphicon-ok").addClass("glyphicon-remove");
  151. },
  152. drop:function(e, ui){
  153. var ref = $("#paramtree").jstree(true);
  154. var node = ref.get_node(ui.draggable[0]);
  155. var tp = node.li_attr.tp;
  156. if(tp == "param"){
  157. $("#optparam").css("border", "1px solid #d3d3d3");
  158. var node = ref.get_node(ui.draggable[0]);
  159. ts.$parent.$refs['prarmAddForm'].newparam("insert", node.li_attr.ptp);
  160. }
  161. }
  162. });
  163. },
  164. initdset(){
  165. let ref = $("#tabletree").jstree(true);
  166. if(ref){
  167. ref.destroy();
  168. }
  169. if (!this.pageInfo.table) {
  170. $('#tabletree').jstree({
  171. core: {
  172. data: {
  173. id: 'nodata',
  174. text: '您还未选择数据集',
  175. icon: 'fa fa-warning icon_kpi'
  176. }
  177. },
  178. "plugins": ["wholerow"]
  179. });
  180. return;
  181. } else {
  182. const dragfunc = () => {
  183. $("#tabletree .jstree-node").draggable({
  184. cursor: "point",
  185. appendTo: "body",
  186. revert: 'invalid',
  187. revertDuration: 250,
  188. cursorAt: { top: 0, left: -35 },
  189. helper:function(e){
  190. var id = $(this).find("a.jstree-anchor:first").text();
  191. return "<div class=\"vakata-dnd\"><span class=\"miconcancel glyphicon glyphicon-remove\"></span>"+id+"</div>";
  192. },
  193. start:function(e){
  194. var ref = $('#tabletree').jstree(true),node = ref.get_node(this);
  195. var attr = node.li_attr;
  196. delete attr.id;
  197. if($.isEmptyObject(attr)){
  198. return false;
  199. }
  200. return true;
  201. }
  202. });
  203. }
  204. let table = this.pageInfo.table;
  205. var dt = {id:table.dsetId, text:table.dsetName+"("+table.priTable+")", state:{opened:true},icon:'fa fa-table', children:[]};;
  206. ajax({
  207. url:"model/getDatasetCfg.action",
  208. type:"GET",
  209. data:{dsetId:table.dsetId},
  210. success:(resp)=>{
  211. let ret = resp.rows.cols;
  212. for(let i=0; i<ret.length; i++){
  213. dt.children.push({id:ret[i].name, text:ret[i].name, icon:'icon_kpi glyphicon glyphicon-menu-hamburger',li_attr:{id:ret[i].name,name:ret[i].name,dsetId:table.dsetId,dsid:table.dsid, tname:ret[i].tname,type:ret[i].type, expression: ret[i].expression}});
  214. }
  215. //添加动态字段
  216. let dyna = resp.dynamic;
  217. for(let i=0; dyna&&dyna!=null&&i<dyna.length; i++){
  218. var r = dyna[i];
  219. dt.children.push({id:r.name, text:r.name, icon:'icon_kpi glyphicon glyphicon-menu-hamburger',li_attr:{id:r.name,name:r.name,dsetId:table.dsetId,dsid:table.dsid, tname:r.tname,type:r.type, expression: r.expression}});
  220. }
  221. $('#tabletree').jstree({
  222. core: {
  223. data: [dt],
  224. check_callback: false
  225. },
  226. "plugins": ["wholerow"]
  227. }).bind("ready.jstree", function (a, b) {
  228. dragfunc();
  229. }).bind("after_open.jstree", function () {
  230. dragfunc();
  231. });
  232. }
  233. }, this);
  234. }
  235. },
  236. initcubes(){
  237. let ref = $("#datasettree").jstree(true);
  238. if(ref){
  239. ref.destroy();
  240. }
  241. if (!this.pageInfo.selectDs) {
  242. $('#datasettree').jstree({
  243. core: {
  244. data: {
  245. id: 'nodata',
  246. text: '您还未选择立方体',
  247. icon: 'fa fa-warning icon_kpi'
  248. }
  249. },
  250. "plugins": ["wholerow"]
  251. });
  252. return;
  253. } else {
  254. const dragfunc = () => {
  255. $("#datasettree .jstree-node").draggable({
  256. cursor: "point",
  257. appendTo: "body",
  258. revert: 'invalid',
  259. revertDuration: 250,
  260. cursorAt: { top: 0, left: -35 },
  261. helper:function(e){
  262. var id = $(this).find("a.jstree-anchor:first").text();
  263. return "<div class=\"vakata-dnd\"><span class=\"miconcancel glyphicon glyphicon-remove\"></span>"+id+"</div>";
  264. },
  265. start:function(e){
  266. var ref = $('#datasettree').jstree(true),node = ref.get_node(this);
  267. var attr = node.li_attr;
  268. delete attr.id;
  269. if($.isEmptyObject(attr)){
  270. return false;
  271. }
  272. return true;
  273. }
  274. });
  275. }
  276. $('#datasettree').jstree({
  277. core: {
  278. data: {
  279. url: 'model/treeCube.action?cubeId=' + this.pageInfo.selectDs + '&t=' + Math.random()
  280. },
  281. check_callback: false
  282. },
  283. "plugins": ["wholerow"]
  284. }).bind("ready.jstree", function (a, b) {
  285. dragfunc();
  286. }).bind("after_open.jstree", function () {
  287. dragfunc();
  288. });
  289. }
  290. }
  291. },
  292. watch: {
  293. },
  294. beforeMount(){
  295. },
  296. beforeDestroy(){
  297. }
  298. }
  299. </script>
  300. <style lang="less" scoped>
  301. @import "../../style/mixin";
  302. .layout-left {
  303. position: fixed;
  304. width: 220px;
  305. height: calc(100% - 35px);
  306. border-right: 1px solid #D3D3D3;
  307. padding-top: 3px;
  308. background-color: white;
  309. }
  310. .layout-left .nav-tabs > li > a {
  311. padding: 5px 10px 5px 10px;
  312. width:70px;
  313. text-align: center;
  314. font-size: 13px;
  315. color: #A7B1C2;
  316. font-weight: 600;
  317. cursor: pointer;
  318. }
  319. .nav-tabs > li.active > a {
  320. color: #555555;
  321. cursor: default;
  322. }
  323. </style>
  324. <style lang="less">
  325. .comp_color {
  326. color:#23b7e5;
  327. }
  328. </style>