Grid.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div style="margin:10px;">
  3. <div class="tableDatasty" id="gridData">
  4. <template v-if="!comp.cols || comp.cols.length === 0">
  5. <div class="tipinfo">拖拽数据表字段到此处作为表格的列字段</div>
  6. </template>
  7. <template v-if="comp.cols && comp.cols.length > 0">
  8. <b>
  9. 表格字段:
  10. </b>
  11. <template v-for="item in comp.cols">
  12. <span :key="item.id" class="dimcol">
  13. <span class="text">{{item.name}}</span>
  14. <div class="ibox-tools"><button class="btn btn-outline btn-success btn-xs"><i class="fa fa-wrench"></i></button>
  15. </div>
  16. </span>
  17. </template>
  18. </template>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import {baseUrl} from '@/common/biConfig'
  24. import $ from 'jquery'
  25. import * as utils from '@/view/portal/Utils'
  26. export default {
  27. components:{
  28. },
  29. props:{
  30. comp:{
  31. type:Object,
  32. required:true
  33. }
  34. },
  35. data(){
  36. return {
  37. }
  38. },
  39. mounted(){
  40. this.bindDropEvent();
  41. },
  42. computed: {
  43. },
  44. methods: {
  45. setUpdate(){
  46. this.$parent.$parent.isupdate = true;
  47. },
  48. gridView(){
  49. this.$parent.$parent.$refs['optarea'].$refs['mv_'+this.comp.id].gridView();
  50. },
  51. bindDropEvent(){
  52. let ts = this;
  53. $("#gridData").droppable({
  54. accept:"#tabletree .jstree-node",
  55. tolerance:"pointer",
  56. over:function(e, ui){
  57. //对维度拖拽设置图标
  58. $(ui.helper[0]).find("span").removeClass("glyphicon-remove").addClass("glyphicon-ok");
  59. $("#gridData").css("border", "1px solid #ff0000");
  60. },
  61. out:function(e, ui){
  62. $(ui.helper[0]).find("span").removeClass("glyphicon-ok").addClass("glyphicon-remove");
  63. $("#gridData").css("border", "1px dotted #666");
  64. },
  65. drop:function(e, ui){
  66. let grid = ts.comp;
  67. //清除边框颜色
  68. $("#gridData").css("border", "1px dotted #666");
  69. //获取TREE
  70. var ref = $("#tabletree").jstree(true);
  71. var node = ref.get_node(ui.draggable[0]);
  72. if(grid.dsetId && grid.dsetId != node.li_attr.dsetId){
  73. utils.msginfo("你拖入的字段"+node.text+"与表格已有的内容不在同一个表中,拖放失败!");
  74. return;
  75. }else{
  76. grid.dsetId = node.li_attr.dsetId;
  77. grid.dsid = node.li_attr.dsid;
  78. }
  79. if(!grid.cols){
  80. grid.cols = [];
  81. }
  82. //判断是否存在
  83. var exist = function(gid){
  84. var r = false;
  85. for(let j=0; j<grid.cols.length; j++){
  86. if(grid.cols[j].id == gid){
  87. r = true;
  88. break;
  89. }
  90. }
  91. return r;
  92. };
  93. if(exist(node.id)){
  94. utils.msginfo("您拖拽的字段 " + node.text+" 已经存在。");
  95. return;
  96. }
  97. grid.cols.push({id:node.id,name:node.li_attr.name,tname:node.li_attr.tname,type:node.li_attr.type,expression:node.li_attr.expression});
  98. ts.setUpdate();
  99. ts.gridView();
  100. }
  101. });
  102. }
  103. },
  104. watch: {
  105. }
  106. }
  107. </script>
  108. <style lang="less" scoped>
  109. .tipinfo {
  110. color:#999;
  111. padding:10px;
  112. }
  113. .tableDatasty{
  114. border: 1px dotted #666;
  115. padding:5px;
  116. border-radius:5px;
  117. .col {
  118. border: 1px solid #DF7809;
  119. display: inline-block;
  120. margin: 5px;
  121. padding: 5px;
  122. text-align: center;
  123. width:120px;
  124. font-size:14px;
  125. border-radius:5px;
  126. }
  127. .dimcol {
  128. border: 1px solid #0C6ADF;
  129. display: inline-block;
  130. margin: 5px;
  131. padding: 5px;
  132. text-align: left;
  133. font-size:14px;
  134. width:120px;
  135. border-radius:5px;
  136. }
  137. }
  138. .ibox-tools {
  139. display: inline-block;
  140. float: right;
  141. margin-top: 0;
  142. position: relative;
  143. padding: 0;
  144. }
  145. </style>