share.vue
5.89 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
<el-dialog
class="tree_dialog"
:title="titleBuild()"
width="30%"
:close-on-click-modal="false"
center
:visible.sync="visib"
:before-close="closeDialog"
>
<div v-if="shareLinkFlag1">
<el-form
ref="userForm"
:model="dialogForm"
:rules="rules"
size="small"
label-width="100px"
>
<el-form-item label="有效期" prop="shareValidType">
<el-select
v-model.trim="dialogForm.shareValidType"
placeholder="请选择"
clearable
@change="selectChange"
>
<el-option
v-for="item in shareValidTypeOptions"
:key="item.id"
:label="item.text"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="分享码" prop="sharePasswordFlag">
<el-switch v-model="dialogForm.sharePasswordFlag"> </el-switch>
</el-form-item>
</el-form>
<el-button
type="primary"
plain
@click="createShare"
style="margin-left:45px"
>创建链接</el-button
>
</div>
<div v-else>
<el-form
ref="userForm"
:model="dialogForm"
:rules="rules"
size="small"
label-width="100px"
>
<el-form-item label="链接" prop="reportShareUrl">
<el-input v-model="reportShareUrl" :disabled="true" />
</el-form-item>
<el-form-item
v-if="dialogForm.sharePasswordFlag"
label="分享码"
prop="sharePassword"
>
<el-input v-model="dialogForm.sharePassword" :disabled="true" />
</el-form-item>
<el-row :gutter="10">
<el-button
v-if="dialogForm.sharePassword == ''"
type="primary"
plain
@click="copyShare"
style="margin-left:45px"
>复制链接</el-button
>
<el-button
v-if="dialogForm.sharePassword != ''"
type="primary"
plain
@click="copyShare"
style="margin-left:45px"
>复制链接和分享码</el-button
>
</el-row>
</el-form>
</div>
<div slot="footer" style="text-align: center">
<!-- <el-button type="primary" plain @click="saveReportShare">保存</el-button>-->
<el-button type="danger" plain @click="closeDialog">取消</el-button>
</div>
</el-dialog>
</template>
<script>
import { excelShareAdd } from "@/api/reportShare";
import { getDictList } from "@/api/dict-data"; // 获取数据字典
import Dictionary from "@/components/Dictionary/index";
export default {
components: { Dictionary },
props: {
visib: {
required: true,
type: Boolean,
default: false
},
reportCode: {
required: true,
type: String,
default: () => {
return "";
}
},
reportName: {
required: true,
type: String,
default: () => {
return "";
}
},
reportType: {
required : true,
type: String,
default: () =>{
return "";
}
}
},
data() {
return {
title: "报表分享",
reportShareUrl: "",
shareValidTypeOptions: [], // 有效期类型
dialogForm: {
shareValidType: 0,
reportCode: "",
reportType: "",
shareUrl: "",
shareCode: "",
sharePassword: "",
sharePasswordFlag: false
},
shareLinkFlag1: true,
rules: {
shareValidType: [
{ required: true, message: "有效期必选", trigger: "change" }
]
}
};
},
watch: {
visib(val) {
if (val) {
// 弹窗弹出时需要执行的逻辑
this.getSystem();
}
}
},
created() {},
methods: {
titleBuild() {
return "【" + this.reportName + "】" + "报表分享";
},
selectChange(val) {
this.dialogForm.shareValidType = val;
},
// 获取数据字典
async getSystem() {
this.shareLinkFlag1 = true;
const { code, data } = await getDictList("SHARE_VAILD");
if (code != "200") return;
this.shareValidTypeOptions = data;
this.dialogForm.shareValidType = this.shareValidTypeOptions[0].id;
this.dialogForm.sharePasswordFlag = false;
this.dialogForm.sharePassword = "";
},
async createShare() {
this.dialogForm.reportType = this.reportType;
this.dialogForm.reportCode = this.reportCode;
this.dialogForm.shareUrl = window.location.href;
const { code, data } = await excelShareAdd(this.dialogForm);
if (code != "200") return;
this.shareLinkFlag1 = false;
this.$message({
message: "创建链接成功!",
type: "success"
});
this.reportShareUrl = data.shareUrl;
this.dialogForm.sharePassword = data.sharePassword;
},
copyShare() {
let content = "";
if (this.dialogForm.sharePassword == "") {
content = "分享链接:" + this.reportShareUrl;
} else {
content =
"分享链接:" +
this.reportShareUrl +
" 分享码:" +
this.dialogForm.sharePassword;
}
this.copyToClip(content);
this.$message({
message: "复制链接成功!",
type: "success"
});
},
copyToClip(content, message) {
let aux = document.createElement("input");
aux.setAttribute("value", content);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
},
async saveReportShare() {
let params = {};
//const { code } = await saveAuthorityTree(params)
//if (code != '200') return
this.closeDialog();
},
// 弹窗关闭之前需要执行的逻辑
closeDialog() {
this.$emit("handleClose");
}
}
};
</script>