Utils.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import $ from 'jquery'
  2. import { Message, Loading } from 'element-ui'
  3. import {baseUrl, ajax} from '@/common/biConfig'
  4. //默认5种布局
  5. export const layout = {
  6. l1 : {tr1:[{colspan:1, rowspan:1, width:100, height:100, id:1}]},
  7. l2 : {tr1:[{colspan:1, rowspan:1, width:50, height:100, id:1},{colspan:1, rowspan:1, width:50, height:100, id:2}]},
  8. l3: {tr1:[{colspan:2, rowspan:1, width:100, height:50, id:1}],tr2:[{colspan:1, rowspan:1, width:50, height:50, id:2},{colspan:1, rowspan:1, width:50, height:50, id:3}]},
  9. l4: {tr1:[{colspan:2, rowspan:1, width:100, height:33, id:1}],tr2:[{colspan:1, rowspan:1, width:50, height:33, id:2},{colspan:1, rowspan:1, width:50, height:33, id:3}], tr3:[{colspan:2, rowspan:1, width:100, height:33, id:4}]},
  10. l5:{tr1:[{colspan:2, rowspan:1, width:100, height:20, id:1}],tr2:[{colspan:1, rowspan:1, width:50, height:20, id:2},{colspan:1, rowspan:1, width:50, height:20, id:3}], tr3:[{colspan:2, rowspan:1, width:100, height:20, id:4}],tr4:[{colspan:1, rowspan:1, width:50, height:20, id:5},{colspan:1, rowspan:1, width:50, height:20, id:6}],tr5:[{colspan:2, rowspan:1, width:100, height:20, id:7}]}
  11. }
  12. export const fmtJson = [{
  13. "text":"整数",
  14. "value":"#,##0"
  15. },{
  16. "text":"小数(保留一位)",
  17. "value":"#,##0.0"
  18. },{
  19. "text":"小数(保留两位)",
  20. "value":"#,##0.00"
  21. },{
  22. "text":"小数(保留四位)",
  23. "value":"#,##0.0000"
  24. },{
  25. "text":"百分比",
  26. "value":"#,##0%"
  27. },{
  28. "text": "百分比(保留一位小数)",
  29. "value": "#,##0.0%"
  30. }, {
  31. "text": "百分比(保留两位小数)",
  32. "value": "#,##0.00%"
  33. }, {
  34. "text": "百分比(保留四位小数)",
  35. "value": "#,##0.0000%"
  36. }];
  37. export const rates = [{
  38. "text":"1",
  39. "value":"1"
  40. },{
  41. "text":"千",
  42. "value":"1000"
  43. },{
  44. "text":"万",
  45. "value":"10000"
  46. },{
  47. "text":"百万",
  48. "value":"1000000"
  49. },{
  50. "text":"亿",
  51. "value":"100000000"
  52. }];
  53. export const pielabels = [{"text":"名称","value":"n"},{"text":"名称+值","value":"nv"},{"text":"名称+比例","value":"np"}];
  54. export const legendpos = [{text: '右上', value: 'righttop'},{text: '中上', value: 'centertop'},{text: '中下', value: 'centerbottom'}];
  55. export const msginfo = (msg, type)=>{
  56. if(!type || type === 'error'){
  57. Message.error({message:msg, type:"error",showClose: true});
  58. }else{
  59. Message.success({message:msg, type:"success",showClose: true});
  60. }
  61. }
  62. export const findParamById = (pageInfo, id, retIndex) => {
  63. var ret = null;
  64. for(let i=0; pageInfo.params&&i<pageInfo.params.length; i++){
  65. var p = pageInfo.params[i];
  66. if(p.id == id){
  67. if(retIndex){
  68. ret = i;
  69. }else{
  70. ret = p;
  71. }
  72. }
  73. }
  74. return ret;
  75. }
  76. export const getParamTypeDesc = (paramType)=>{
  77. var tpname = "";
  78. if(paramType == "text"){
  79. tpname = "输入框";
  80. }else if(paramType == "radio"){
  81. tpname = "单选框";
  82. }else if(paramType == "checkbox"){
  83. tpname = "多选框";
  84. }else if(paramType == "dateselect"){
  85. tpname = "日历框";
  86. }else if(paramType == "monthselect"){
  87. tpname = "月份框";
  88. }else if(paramType == "yearselect"){
  89. tpname = "年份框";
  90. }
  91. return tpname;
  92. }
  93. export const getCompTypeDesc = (compType)=>{
  94. var name = "";
  95. if(compType === 'text'){
  96. name = "文本";
  97. }else if(compType === 'box'){
  98. name = "数据块";
  99. }else if(compType === 'chart'){
  100. name = "图形";
  101. }else if(compType === 'grid'){
  102. name = "表格";
  103. }else if(compType === 'table'){
  104. name = "交叉表";
  105. }
  106. return name;
  107. }
  108. //从布局器中查询td(容器)
  109. export const findLayoutById = (layoutId, pageInfo)=>{
  110. var ret = null;
  111. for(var i=1; true; i++){
  112. var tr = pageInfo.body["tr"+i];
  113. if(!tr || tr == null){
  114. break;
  115. }
  116. for(var j=0; j<tr.length; j++){
  117. var td = tr[j];
  118. if(td.id == layoutId){
  119. ret = td;
  120. break;
  121. }
  122. }
  123. }
  124. return ret;
  125. }
  126. //查询布局器中所以组件
  127. export const findAllComps = (pageInfo)=>{
  128. let ret = [];
  129. for(var i=1; true; i++){
  130. var tr = pageInfo.body["tr"+i];
  131. if(!tr || tr == null){
  132. break;
  133. }
  134. for(var j=0; j<tr.length; j++){
  135. var td = tr[j];
  136. if(td.children){
  137. td.children.forEach(element => {
  138. ret.push(element);
  139. });
  140. }
  141. }
  142. }
  143. return ret;
  144. }
  145. /**
  146. //从布局器中查询组件
  147. * @param {*} pageInfo
  148. * @param {*} compId
  149. * @param {*} remove 是否移除查找到的对象
  150. */
  151. export const findCompById = (pageInfo, compId, remove)=>{
  152. let ret = null;
  153. for(var i=1; true; i++){
  154. var tr = pageInfo.body["tr"+i];
  155. if(!tr || tr == null){
  156. break;
  157. }
  158. for(var j=0; j<tr.length; j++){
  159. var td = tr[j];
  160. if(td.children){
  161. $(td.children).each((a, b)=>{
  162. if(b.id === compId){
  163. ret = b;
  164. if(remove){
  165. td.children.splice(a, 1);
  166. }
  167. return false;
  168. }
  169. });
  170. }
  171. }
  172. }
  173. return ret;
  174. }
  175. /**
  176. * 组件事件调用,目前只支持图形,交叉表
  177. * @param {*} link
  178. */
  179. export const compFireEvent = (link, ts, paramName, value)=>{
  180. let target = link.target;
  181. let types = link.type.split(",");
  182. $(target.split(",")).each((a, b)=>{
  183. let loadingInstance = Loading.service({fullscreen:false, target:document.querySelector('#c_'+b+" div.ccctx")});
  184. let dt = ts.$parent.$parent.$refs['paramViewForm'].getParamValues(); // 获取参数
  185. let tp = types[a];
  186. if(tp === 'chart'){
  187. dt['serviceid'] = "ext.sys.chart.rebuild";
  188. }else if(tp ==='table'){
  189. dt['serviceid'] = "ext.sys.cross.rebuild";
  190. }
  191. dt['t_from_id'] = "mv_" + ts.$parent.pageInfo.id;
  192. dt['id'] = b;
  193. dt[paramName] = value;
  194. ajax({
  195. url:"control/extControl",
  196. type:"POST",
  197. data:dt,
  198. success:(resp)=>{
  199. loadingInstance.close();
  200. if(tp === 'chart'){
  201. //更新图形
  202. let c = ts.$parent.$refs['mv_'+b];
  203. c.data = resp.rows;
  204. c.$nextTick(()=>c.showChart());
  205. }else if(tp === 'table'){
  206. }
  207. }
  208. }, ts, loadingInstance);
  209. });
  210. }