frameEditor.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <!-- 添加编辑框架 -->
  3. <div class="frame-editor-wrap">
  4. <div class="option-wrap">
  5. <el-input style="width:240px;" placeholder="请输入框架名称" v-model.trim="frameDetail.FrameworkName"></el-input>
  6. <el-button type="primary" style="margin-left:auto;" @click="handleEditNode({})"
  7. v-if="permissionBtn.isShowBtn('chartFramePermission','chartframe_my_editNode')">添加节点</el-button>
  8. <el-button type="primary" style="margin-left:20px;" @click="saveFrame"
  9. v-if="permissionBtn.isShowBtn('chartFramePermission','chartframe_my_saveFrame')">保存</el-button>
  10. </div>
  11. <div class="editor-wrap">
  12. <!-- 沙盘图组件 -->
  13. <FrameContainer ref="container"
  14. :FrameworkContent="frameDetail.FrameworkContent"
  15. @editNode="handleEditNode"
  16. @framePic="getFramePic"
  17. />
  18. </div>
  19. <!-- 添加/编辑节点弹窗 -->
  20. <el-dialog
  21. :title="modifyNode.nodeId?'编辑节点':'添加节点'"
  22. :visible.sync="isModifyNodeDialogShow"
  23. :close-on-click-modal="false"
  24. :modal-append-to-body="false"
  25. @close="isModifyNodeDialogShow=false"
  26. width="589px"
  27. v-dialogDrag
  28. center
  29. >
  30. <div class="dialog-container">
  31. <el-form
  32. ref="refForm"
  33. :model="modifyNode"
  34. :rules="rules"
  35. >
  36. <el-form-item label="节点名称" prop="nodeName">
  37. <el-input v-model.trim="modifyNode.nodeName" placeholder="请输入节点名称" style="width:217px;"></el-input>
  38. </el-form-item>
  39. <el-form-item label="节点链接" prop="nodeLink">
  40. <el-select v-model="modifyNode.nodeLink" value-key="MyChartClassifyId" placeholder="请选择节点链接" style="width:217px;">
  41. <el-option v-for="item in myList"
  42. :key="item.MyChartClassifyId"
  43. :label="item.MyChartClassifyName"
  44. :value="item">
  45. <span style="float:left;">{{item.MyChartClassifyName}}</span>
  46. <span style="float:right;color: #8492a6; font-size: 13px"
  47. @click="goToList(item)"><img src="~@/assets/img/chart_m/check.png"></span>
  48. </el-option>
  49. </el-select>
  50. </el-form-item>
  51. </el-form>
  52. </div>
  53. <div class="dialog-footer">
  54. <el-button @click="isModifyNodeDialogShow=false">取消</el-button>
  55. <el-button type="primary" @click="editNode">确定</el-button>
  56. </div>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. import FrameContainer from './components/frameContainer.vue';
  62. import { mychartInterface,chartFrameInterface,dataBaseInterface } from '@/api/api.js';
  63. export default {
  64. components: { FrameContainer },
  65. data() {
  66. return {
  67. frameId:this.$route.query.frameId||0,
  68. frameDetail:{
  69. FrameworkName:'',
  70. FrameworkContent:'',
  71. },
  72. lockLoding:null,
  73. modifyNode: {},//正在编辑的节点
  74. isModifyNodeDialogShow: false,//编辑节点弹窗
  75. rules: {
  76. nodeName: [{ required: true, message: "请输入节点名称", trigger: "blur" }],
  77. nodeLink: [{ required: true, message: "请选择节点链接", trigger: "blur" }]
  78. },
  79. myList:[],//我的图库列表
  80. };
  81. },
  82. methods: {
  83. //获取正在编辑的节点,弹出弹窗
  84. handleEditNode(node = {}) {
  85. this.$refs.refForm && this.$refs.refForm.resetFields();
  86. this.modifyNode = _.cloneDeep(node);
  87. this.isModifyNodeDialogShow = true;
  88. },
  89. //编辑节点,更改子组件节点信息,隐藏弹窗
  90. async editNode() {
  91. await this.$refs.refForm.validate();
  92. if(!this.$refs.container) return
  93. this.$refs.container.editNode(this.modifyNode)
  94. this.$message.success(`${this.modifyNode.nodeId ? '编辑' : '添加'}节点成功`);
  95. this.isModifyNodeDialogShow = false;
  96. },
  97. //跳转至my eta
  98. goToList(item) {
  99. window.open(`/mychart?frameId=${item.MyChartClassifyId}`);
  100. },
  101. //保存框架:内容验证->生成缩略图->获取节点信息,内容信息->编辑/添加框架
  102. async saveFrame(){
  103. if(!this.frameDetail.FrameworkName.length){
  104. return this.$message.warning("请输入框架名称")
  105. }
  106. if(!this.$refs.container.graph.toJSON().cells.length){
  107. return this.$message.warning('请绘制画布内容');
  108. }
  109. this.lockLoding = this.$loading({
  110. lock: true,
  111. text: '保存中...',
  112. target: '.frame-editor-wrap',
  113. spinner: 'el-icon-loading',
  114. background: 'rgba(255, 255, 255, 0.8)'
  115. });
  116. //获取框架内容图片
  117. const svgData = this.$refs.container.getContentPic()
  118. if(svgData){
  119. const params = new FormData();
  120. params.append('Img',svgData)
  121. const { Data,Ret } = await dataBaseInterface.uploadImgSvg(params);
  122. if(Ret !== 200) return;
  123. if(!Data){
  124. return this.$message.warning("上传图片失败")
  125. }
  126. this.frameDetail.FrameworkImg = Data.ResourceUrl||''
  127. }
  128. //获取框架节点和内容
  129. this.frameDetail.Nodes = this.$refs.container.getContentNodes()
  130. this.frameDetail.FrameworkContent = JSON.stringify(this.$refs.container.graph.toJSON())
  131. if(this.frameId){
  132. //edit
  133. chartFrameInterface.editFrame({...this.frameDetail,...{ChartFrameworkId:Number(this.frameId)}}).then(res=>{
  134. this.lockLoding.close();
  135. if(res.Ret!==200) return
  136. this.$message.success("编辑成功")
  137. })
  138. }else{
  139. //add
  140. chartFrameInterface.addFrame(this.frameDetail).then(res=>{
  141. this.lockLoding.close();
  142. if(res.Ret!==200) return
  143. this.frameId = res.Data?res.Data.ChartFrameworkId:0
  144. this.frameDetail = res.Data||{FrameworkName:'',FrameworkContent:''}
  145. this.$message.success("新增成功")
  146. //切换至编辑页
  147. this.$router.replace({path:'/editframe',query:{frameId:this.frameId}})
  148. })
  149. }
  150. },
  151. getMyList(){
  152. mychartInterface.classifyList().then((res)=>{
  153. if(res.Ret!==200) return
  154. if(!res.Data) return
  155. this.myList = res.Data.List||[]
  156. })
  157. },
  158. async getFrameDetail(){
  159. if(this.frameId){
  160. const res = await chartFrameInterface.getFrameDetail({ChartFrameworkId:Number(this.frameId)})
  161. if(res.Ret!==200) return
  162. this.frameDetail = res.Data||{FrameworkName:'',FrameworkContent:''}
  163. }
  164. //获取到框架内容后再加载graph
  165. this.$nextTick(()=>{
  166. this.$refs.container.init()
  167. })
  168. },
  169. },
  170. mounted(){
  171. this.getMyList()
  172. this.getFrameDetail()
  173. }
  174. };
  175. </script>
  176. <style scoped lang="scss">
  177. .frame-editor-wrap{
  178. display: flex;
  179. flex-direction: column;
  180. height: calc(100vh - 120px);
  181. *{box-sizing: border-box;}
  182. .option-wrap{
  183. background-color:#fff;
  184. padding:20px;
  185. display: flex;
  186. justify-content: space-between;
  187. }
  188. .editor-wrap{
  189. margin-top: 15px;
  190. flex: 1;
  191. display: flex;
  192. flex-direction: column;
  193. background-color: #fff;
  194. overflow: hidden;
  195. .frame-wrap{
  196. flex:1;
  197. background-color: #F2F6FA;
  198. }
  199. }
  200. .el-dialog{
  201. .dialog-container{
  202. .el-form{
  203. .el-form-item{
  204. display: flex;
  205. justify-content: center;
  206. }
  207. }
  208. }
  209. .dialog-footer{
  210. text-align: center;
  211. padding-bottom:25px;
  212. }
  213. }
  214. }
  215. </style>