LowcodeExample.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div id="lowcode-box" />
  3. </template>
  4. <script>
  5. // import 'lowcode/sdk/sdk.js';
  6. // import 'lowcode/lib/themes/antd.css';
  7. // import 'lowcode/lib/helper.css';
  8. // import 'lowcode/sdk/iconfont.css';
  9. import { lowcodeConfig } from './LowcodeConfig.js';
  10. import LowcodeWindowResource from '../api/dic/LowcodeWindowResource.js';
  11. import Common from '../base/common/Common.js';
  12. import { Notify, Uuid } from 'pc-component-v3';
  13. export default {
  14. name: 'LowcodeExample',
  15. watch: {
  16. '$route': function (to, from) {
  17. let lowcodeWindowNo = this.$route.params.no;
  18. if(lowcodeWindowNo != null && lowcodeWindowNo != undefined){
  19. this.init();
  20. }
  21. },
  22. },
  23. mounted(){
  24. let _self = this;
  25. this.$nextTick(function(){
  26. let lowcodeWindowNo = this.$route.params.no;
  27. if(lowcodeWindowNo != null && lowcodeWindowNo != undefined){
  28. this.init();
  29. }
  30. });
  31. },
  32. beforeUnmount(){
  33. // 销毁 lowcode
  34. this.destory();
  35. },
  36. methods: {
  37. /**
  38. * 初始化lowcode实例
  39. */
  40. init(){
  41. // 初始化lowcode实例之前,先判断是否已经有lowcode实例,如果有的话就销毁。
  42. this.destory();
  43. let lowcodeWindowNo = this.$route.params.lowcodeWindowNo;
  44. let lowcode = window.lowcodeRequire('lowcode/embed');
  45. let _self = this;
  46. LowcodeWindowResource.readJson(lowcodeWindowNo).then(baseObjectResponse => {
  47. if(baseObjectResponse.errorCode === 0){
  48. let lowcodeJSON = JSON.parse(baseObjectResponse.data);
  49. _self.lowcodeScoped = lowcode.embed('#lowcode-box', lowcodeJSON, {}, lowcodeConfig);
  50. }else{
  51. let lowcodeJSON = {};
  52. Notify.error('提示', baseObjectResponse.errorMessage, false);
  53. }
  54. },errorData => {
  55. Common.processException(errorData);
  56. });
  57. },
  58. /**
  59. * 销毁lowcode实例
  60. */
  61. destory(){
  62. let _self = this;
  63. if(_self.lowcodeScoped != null){
  64. _self.lowcodeScoped.unmount();
  65. _self.lowcodeScoped = null;
  66. }
  67. },
  68. },
  69. };
  70. </script>