sand.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // 沙盘
  2. import { configOpt,styleSettings } from '@/views/sandbox_manage/common/toolConfig';
  3. const setSandboxToolStatus=(state,payload)=>{
  4. console.log(payload,'payload',state);
  5. if(!(payload&&payload.length>0)){
  6. state.toolStatus.textDisabled=true
  7. state.toolStatus.edgeDisabled=true
  8. state.toolStatus.nodeDisabled=true
  9. state.styleOptions={
  10. fontF:"微软雅黑",
  11. fontS:18,
  12. fontW:'normal',
  13. fontStyle:'normal',
  14. textDecoration:'none',
  15. color:'#333333',
  16. lineHeight:1.3,
  17. textAlign:'none',
  18. backgroundColor:'#DAE8FF',
  19. lineColor:'#0052D9',
  20. lineStyle:null,
  21. lineWidth:2,
  22. connectStyle:1,
  23. startArrow:'',
  24. endArrow:''
  25. }
  26. return
  27. }else{
  28. const fontFamilySet=new Set(),fontSizeSet=new Set(),fontWeightSet=new Set(),fontStyleSet=new Set(),
  29. textDecorationSet=new Set(),colorSet=new Set(),lineHeightSet=new Set(),
  30. textAlignSet=new Set(),backgroundColorSet=new Set(),lineColorSet=new Set(),
  31. lineStyleSet=new Set(),lineWidthSet=new Set(),connectStyleSet=new Set(),
  32. startArrowSet=new Set(),endArrowSet=new Set()
  33. for (let i = 0; i < payload.length; i++) {
  34. const element = payload[i];
  35. const attrs = element.getAttrs()
  36. console.log(element.shape);
  37. if(element.shape.indexOf('edge')==-1){
  38. state.toolStatus.textDisabled=false
  39. state.toolStatus.edgeDisabled=true
  40. fontFamilySet.add(attrs.text.fontFamily)
  41. fontSizeSet.add(attrs.text.fontSize)
  42. fontWeightSet.add(attrs.text.fontWeight)
  43. fontStyleSet.add(attrs.text.fontStyle)
  44. textDecorationSet.add(attrs.text.textDecoration)
  45. colorSet.add(attrs.text.fill)
  46. lineHeightSet.add(Math.round((attrs.text.lineHeight/attrs.text.fontSize)*10)/10)
  47. textAlignSet.add(attrs.text.textAnchor)
  48. if(!(element.data) || element.data.key!='text'){
  49. // console.log('不是text');
  50. backgroundColorSet.add(attrs.body.fill)
  51. lineColorSet.add(attrs.body.stroke)
  52. lineStyleSet.add(attrs.body.strokeDasharray)
  53. lineWidthSet.add(attrs.body.strokeWidth)
  54. state.toolStatus.nodeDisabled=false
  55. }else{
  56. state.toolStatus.nodeDisabled=true
  57. }
  58. }else{
  59. state.toolStatus.edgeDisabled=false
  60. state.toolStatus.textDisabled=true
  61. state.toolStatus.nodeDisabled=true
  62. lineColorSet.add(attrs.line.stroke)
  63. lineStyleSet.add(attrs.line.strokeDasharray)
  64. lineWidthSet.add(attrs.line.strokeWidth)
  65. startArrowSet.add(attrs.line.sourceMarker)
  66. endArrowSet.add(attrs.line.targetMarker)
  67. const router = element.getRouter()
  68. const connector = element.getConnector()
  69. console.log(router,connector,'router,connector');
  70. if(router && router.name=="normal"){
  71. connectStyleSet.add(1)
  72. }else{
  73. if((!connector) || connector.name == 'normal'){
  74. connectStyleSet.add(2)
  75. }else{
  76. connectStyleSet.add(3)
  77. }
  78. }
  79. }
  80. }
  81. // 设置fontFamily回显
  82. state.styleOptions.fontF=fontFamilySet.size==1?Array.from(fontFamilySet)[0]:"微软雅黑"
  83. // 设置fontSize回显
  84. state.styleOptions.fontS=fontSizeSet.size==1?Array.from(fontSizeSet)[0]:18
  85. // 设置fontWeight回显
  86. state.styleOptions.fontW=fontWeightSet.size==1?Array.from(fontWeightSet)[0] || 'normal':"normal"
  87. // 设置fontStyle回显
  88. state.styleOptions.fontStyle=fontStyleSet.size==1?Array.from(fontStyleSet)[0] || 'normal':"normal"
  89. // 设置textDecoration回显
  90. state.styleOptions.textDecoration=textDecorationSet.size==1?Array.from(textDecorationSet)[0] || 'none':"none"
  91. // 设置color回显
  92. state.styleOptions.color=colorSet.size==1?Array.from(colorSet)[0]:"#333333"
  93. // 设置lineHeight回显
  94. state.styleOptions.lineHeight=lineHeightSet.size==1?Array.from(lineHeightSet)[0]:1.3
  95. // 设置textAlign回显
  96. state.styleOptions.textAlign=textAlignSet.size==1?Array.from(textAlignSet)[0]:'none'
  97. // 设置backgroundColor回显
  98. state.styleOptions.backgroundColor=backgroundColorSet.size==1?Array.from(backgroundColorSet)[0]:'#DAE8FF'
  99. // 设置lineColor回显
  100. state.styleOptions.lineColor=lineColorSet.size==1?Array.from(lineColorSet)[0]:'#0052D9'
  101. // 设置lineStyle回显
  102. state.styleOptions.lineStyle=lineStyleSet.size==1?Array.from(lineStyleSet)[0]:null
  103. // 设置lineWidth回显
  104. state.styleOptions.lineWidth=lineWidthSet.size==1?Array.from(lineWidthSet)[0]:2
  105. // 设置connectStyle回显
  106. state.styleOptions.connectStyle=connectStyleSet.size==1?Array.from(connectStyleSet)[0]:1
  107. // 设置sourceMarker回显
  108. state.styleOptions.startArrow=startArrowSet.size==1?Array.from(startArrowSet)[0]||'':''
  109. // 设置targetMarker回显
  110. state.styleOptions.endArrow=endArrowSet.size==1?Array.from(endArrowSet)[0]||'':''
  111. }
  112. }
  113. const sand = {
  114. namespaced: true,
  115. state: () => ({
  116. initConfig: {
  117. ...configOpt
  118. },//默认工具栏配置
  119. DisableText: true,// 禁用文本设置
  120. DisableLine: true, //禁用线条设置
  121. DisableBorder: true, //禁用线框设置
  122. selectCell: null,
  123. // 不同风格
  124. style:1,
  125. styleConfig:{
  126. backgroundColor:'#BBCEFF',
  127. color:'#1841AA',
  128. textColor:'#1841AA',
  129. borderColor:'#1841AA',
  130. lineColor:'#1841AA'
  131. },
  132. toolStatus:{
  133. nodeDisabled:true,
  134. edgeDisabled:true,
  135. textDisabled:true,
  136. },
  137. styleOptions:{
  138. fontF:"微软雅黑",
  139. fontS:18,
  140. fontW:'normal',
  141. fontStyle:'normal',
  142. textDecoration:'none',
  143. color:'#333333',
  144. lineHeight:1.3,
  145. textAlign:'none',
  146. backgroundColor:'#DAE8FF',
  147. lineColor:'#0052D9',
  148. lineStyle:null,
  149. lineWidth:2,
  150. connectStyle:1,
  151. startArrow:'',
  152. endArrow:''
  153. },
  154. selectCells:[]
  155. }),
  156. mutations: {
  157. /* 节点选中 toolbar设置状态 */
  158. SET_SELECT_STATUS(state,payload) {
  159. switch(payload.key) {
  160. case 'rect':
  161. state.DisableText = false;
  162. state.DisableLine = true;
  163. state.DisableBorder = false;
  164. state.initConfig = {
  165. ...configOpt,
  166. ...payload.options
  167. }
  168. break;
  169. case 'date':
  170. state.DisableText = false;
  171. state.DisableLine = true;
  172. state.DisableBorder = false;
  173. state.initConfig = {
  174. ...configOpt,
  175. ...payload.options
  176. }
  177. break;
  178. case 'text':
  179. state.DisableText = false;
  180. state.DisableLine = true;
  181. state.DisableBorder = true;
  182. state.initConfig = {
  183. ...configOpt,
  184. ...payload.options
  185. }
  186. break;
  187. case'line':
  188. state.DisableText = true;
  189. state.DisableLine = false;
  190. state.DisableBorder = true;
  191. state.initConfig = {
  192. ...configOpt,
  193. ...payload.options
  194. }
  195. break;
  196. default:
  197. state.DisableText = true;
  198. state.DisableLine = true;
  199. state.DisableBorder = true;
  200. break;
  201. }
  202. },
  203. /* 设置选中节点 */
  204. SET_SELECT_CELL(state,payload) {
  205. state.selectCell = payload;
  206. },
  207. /* 设置选中节点 */
  208. SET_SELECT_CELLS(state,payload) {
  209. state.selectCells = payload;
  210. // 设置工具状态栏的回显和禁用
  211. setSandboxToolStatus(state,payload)
  212. },
  213. /* 设置加粗样式 */
  214. SET_BOLD_STYLE(state,{attr,val}) {
  215. state.initConfig.text.fontWeight = val;
  216. state.selectCell.attr(`${attr}`,val);
  217. },
  218. // 设置节点风格
  219. SET_CELL_STYLE(state,style){
  220. if(!style) style=1
  221. state.style = style
  222. let styleData = styleSettings[style-1]
  223. state.styleConfig.backgroundColor = styleData.backgroundColor
  224. state.styleConfig.color = styleData.color
  225. state.styleConfig.textColor = styleData.textColor
  226. state.styleConfig.borderColor = styleData.borderColor
  227. state.styleConfig.lineColor = styleData.lineColor
  228. }
  229. },
  230. actions: {
  231. },
  232. getters: {
  233. }
  234. }
  235. export default sand;