|
|
@@ -0,0 +1,85 @@
|
|
|
+<template>
|
|
|
+ <div id="amis-box" />
|
|
|
+</template>
|
|
|
+
|
|
|
+
|
|
|
+<script>
|
|
|
+
|
|
|
+import 'amis/sdk/sdk.js';
|
|
|
+import 'amis/lib/themes/antd.css';
|
|
|
+import 'amis/lib/helper.css';
|
|
|
+import 'amis/sdk/iconfont.css';
|
|
|
+import { amisConfig } from './AmisConfig.js';
|
|
|
+
|
|
|
+var AmisWindowResource = require('./AmisWindowResource.js');
|
|
|
+var Common = require('../../common/Common.js').default;
|
|
|
+var Notify = require('../../common/Notify.js').default;
|
|
|
+
|
|
|
+export default {
|
|
|
+
|
|
|
+ name: 'AmisWidget',
|
|
|
+
|
|
|
+ props: {
|
|
|
+ amisWindowNo: {
|
|
|
+ type: String,
|
|
|
+ default: null,
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ watch: {
|
|
|
+ 'amisWindowNo': function (to, from) {
|
|
|
+ this.init();
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ mounted() {
|
|
|
+ let _self = this;
|
|
|
+ this.$nextTick(function () {
|
|
|
+ _self.init();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化amis实例
|
|
|
+ */
|
|
|
+ init() {
|
|
|
+ if (this.amisWindowNo == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化amis实例之前,先判断是否已经有amis实例,如果有的话就销毁。
|
|
|
+ this.destory();
|
|
|
+
|
|
|
+ let amis = window.amisRequire('amis/embed');
|
|
|
+ let _self = this;
|
|
|
+
|
|
|
+ AmisWindowResource.readJson(this.amisWindowNo).then(baseObjectResponse => {
|
|
|
+ if (baseObjectResponse.errorCode === 0) {
|
|
|
+ let amisJSON = JSON.parse(baseObjectResponse.data);
|
|
|
+ _self.amisScoped = amis.embed('#amis-box', amisJSON, {}, amisConfig);
|
|
|
+ } else {
|
|
|
+ Notify.error('提示', baseObjectResponse.errorMessage, false);
|
|
|
+ }
|
|
|
+ }, errorData => {
|
|
|
+ Common.processException(errorData);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销毁amis实例
|
|
|
+ */
|
|
|
+ destory(){
|
|
|
+ let _self = this;
|
|
|
+ if(_self.amisScoped != null){
|
|
|
+ _self.amisScoped.unmount();
|
|
|
+ _self.amisScoped = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|