wangting
2024-06-14 f8035d6a65d1f610f87fa12408224176f1bf005f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
  <el-dialog v-dialogDrag
             :title="title"
             :visible.sync="visible"
             :width="width"
             :fullscreen="fullscreen"
             :append-to-body="true"
             top="0"
             class="avue-dialog"
             :destroy-on-close="true"
             :close-on-click-modal="false"
             @close="dialogClose">
    <!--窗口显示内容-->
    <!--展示UI上下文-->
    <ui-view ref="uiViewRef" v-if="paramVOS.context"
             :key="'AddDialog-'+paramVOS.context"
             :style="fullscreen?'':'height:'+height"
             :btmType="paramVOS.type"
             :context="paramVOS.context"
             :inDialog="true"
             :canEdit="true"
             :actionType="type"
             :sourceData="sourceData"
             :dataStore="dataStore"
             :paramVOS="paramVOS"
             @getFormData="getFormData"
    ></ui-view>
    <!--非UI上下文-->
    <div v-else>这里是窗口显示内容</div>
 
    <!--底部按钮,非必有-->
    <div class="dialog-footer avue-dialog__footer">
      <el-button type="primary" plain size="small" @click="save" >保 存</el-button>
      <el-button size="small" @click="dialogClose">取 消</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import uiView from "@/views/base/UIContentViewerInDialog"
import {validatenull} from "@/util/validate"
import {parseEventByUrl} from "@/components/actions/BaseAction";
 
export default {
  name: "AddResourceFolderDialog",
  components:{uiView},
  props: {
    sourceData: {
      //所属区域的上一区域选中数据
      type: Object,
      default: {}
    },
    dataStore: {
      //弹窗时按钮所属区域选中数据
      type: Array,
      default: []
    },
    paramVOS: {
      type: Object,
      default: {}
    }
  },
  data(){
    return {
      type: "add",
      visible: false,
      form:{}//表单对象
    }
  },
  computed:{
    title(){
      return this.paramVOS.title || (this.type=='add'?'添加':'修改')
    },
    width() {
      if (!validatenull(this.paramVOS.width)) {
        if (this.paramVOS.width.includes("px") || this.paramVOS.width.includes("%")) {
          return this.paramVOS.width;
        } else {
          return this.paramVOS.width + "px";
        }
      } else {
        return "60%";
      }
    },
    height(){
      if (!validatenull(this.paramVOS.height)) {
        if (this.paramVOS.height.includes("px") || this.paramVOS.height.includes("%")) {
          return this.paramVOS.height;
        } else {
          return this.paramVOS.height + "px";
        }
      } else {
        return "auto"
      }
    },
    fullscreen(){
      if(this.paramVOS.width || this.paramVOS.height){
        return false;
      }else if(this.paramVOS.form){
        return false;
      }
      return true;
    }
  },
  created() {
  },
  watch: {},
  methods: {
    //关闭弹窗
    dialogClose() {
      this.visible = false;
    },
    //保存
    save() {
      //有保存前置事件
      if (this.paramVOS.savebeforeevent) {
        var urlobj = parseEventByUrl(this.paramVOS.savebeforeevent, null, null, 'doAction');
        if(urlobj.params){
          Object.assign(this.paramVOS,urlobj.params);
        }
        if(validatenull(urlobj.jsPath)){
          this.saveBforeHandle(this.paramVOS);
        }else{
          try {
            import(`./${urlobj.jsPath}.js`).then(module => {
              module[urlobj.methodName]({
                paramVOS: this.paramVOS,
                dataStore: this.dataStore,
                sourceData: this.sourceData
              }, this.saveHandle);
            })
          } catch (error) {
            this.$message.error('未找到保存前置事件执行js');
          }
        }
 
      }else{
        //直接保存
        this.saveHandle();
      }
    },
    saveHandle(){
      let that=this;
 
      //执行保存逻辑
 
      //保存成功后
      that.$message({
        type: "success",
        message: that.paramVOS.successmsg||"保存成功!"
      });
      if(that.saveCallback){
        that.saveCallback(that.type);
      }
      if (this.paramVOS.saveafterevent) {
        let urlobj = parseEventByUrl(this.paramVOS.saveafterevent,null,null,'doAction');
        if(urlobj.params){
          Object.assign(this.paramVOS,urlobj.params);
        }
        if(validatenull(urlobj.jsPath)){
          this.saveAfterHandle(this.paramVOS);
        }else{
          try {
            import(`./${urlobj.jsPath}.js`).then(module => {
              module[urlobj.methodName]({
                paramVOS: this.paramVOS,
                dataStore: this.dataStore,
                sourceData:this.sourceData
              });
            })
          } catch (error) {
            this.$message.error('未找到保存后置事件执行js');
          }
        }
 
      }
      that.dialogClose();
    },
    //保存前置事件
    saveBforeHandle(params){
      this.$message.info('执行保存前置事件');
    },
    //保存后置事件
    saveAfterHandle(params){
      this.$message.info('保存后置事件执行');
    },
    getFormData(form) {
      this.form = form;
    }
  }
}
</script>
 
<style scoped>
 
</style>