ApiList.vue
6.71 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
229
230
231
232
233
234
235
236
237
238
239
240
241
<!--
* @Description:
* @Author: huyue
* @Date: 2023-01-30 16:10:23
* @LastEditors: huyue
* @LastEditTime: 2023-07-31 14:51:34
-->
<template>
<div class="api-list">
<h3>项目接口</h3>
<div>
<el-input class="search-input" v-model="apiData.urlInput" clearable placeholder="请输入url" />
<el-button class="search-button" @click="search" type="primary">查询</el-button>
<el-button class="search-button" :isDisabled="disabled" v-preventReClick @click="addFn" type="primary">新建</el-button>
</div>
<el-table border :data="apiData.tableData" stripe style="width: 100%">
<el-table-column prop="url" label="url" />
<el-table-column prop="remark" label="remark" />
<el-table-column prop="username" label="操作人" />
<el-table-column prop="updateDate" label="更新时间" />
<el-table-column label="操作" width="300">
<template #default="scope">
<el-button
type="text"
size="small"
v-preventReClick
@click.prevent="editorRow(scope.row)"
>
{{ disabled ? "查看" : "编辑" }}
</el-button>
<el-button
type="text"
size="small"
v-preventReClick
:disabled="disabled"
@click.prevent="deleteRow(scope.row)"
>
删除
</el-button>
<el-button
type="text"
size="small"
v-preventReClick
@click.prevent="copy(scope.row)"
>
WEB复制链接
</el-button>
<el-button
type="text"
size="small"
v-preventReClick
@click.prevent="copy(scope.row, 'env')"
>
小程序复制链接
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
background
layout="total, prev, pager, next"
:total="apiData.total"
:page-size="apiData.pager.size"
class="mt-4"
@current-change="currentChange"
/>
</div>
</template>
<script lang="ts">
import { reactive } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import "element-plus/theme-chalk/el-message.css";
import "element-plus/theme-chalk/el-message-box.css";
import router from "@/router";
import { ProjectApi, ProjectApiSearch, CopyProject } from "@/type/index";
import { useRoute } from "vue-router";
import { getProjectApiList, projectApiDel, getCopyApi } from "@/api/projectApi";
import config from '../../config/index'
export default {
name: "ApiList",
setup() {
const apiData = reactive({
urlInput: "",
total: 0,
pager: {
page: 1,
size: 20
},
tableData: [],
copyText: ''
})
//获取路由对象
const route = useRoute();
//获取路由参数
let routerParams = route.query;
const userInfo =
window.sessionStorage.getItem("userInfo") &&
JSON.parse(window.sessionStorage.getItem("userInfo") || "");
// 是否管理员
const isAdmin = userInfo && userInfo.roleId === 1 ? true : false;
// const disabled = routerParams.projectId === "1" && !isAdmin ? true : false;
const disabled = userInfo.auth == "readonly" ? true : false;
window.sessionStorage.removeItem("editApiItem");
const addFn = (flag = true, editorItem?: ProjectApi) => {
// 判断是编辑还是新增
if (flag) {
//新增
router.push({
name: "addapi",
query: {
projectId: routerParams.projectId,
baseUrl: routerParams.baseUrl,
},
});
} else {
//编辑
router.push({
name: "addapi",
});
window.sessionStorage.setItem(
"editApiItem",
JSON.stringify(editorItem)
);
}
};
const editorRow = (editorRow: ProjectApi) => {
// console.log("editorRow: ", editorRow);
addFn(false, editorRow);
};
const deleteRow = (editorRow: ProjectApi) => {
console.log("editorRow: ", editorRow);
ElMessageBox.confirm("您确定要删除吗?", "Warning", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
//删除接口
let { code } = await projectApiDel({ id: editorRow.id as number });
if (code === 200) {
//获取数据
getdata();
ElMessage({
type: "success",
message: "删除成功",
});
}
})
.catch(() => {
ElMessage({
type: "info",
message: "取消删除",
});
});
};
//请求数据
const getdata = async () => {
const url = apiData.urlInput
let params: ProjectApiSearch = Object.assign({
projectId: routerParams.projectId,
}, apiData.pager)
if (url) params.url = url;
console.log(params)
let { code, data } = await getProjectApiList(params);
if (code === 200) {
apiData.tableData = data.rows;
apiData.total = data.count
}
};
const search = () => {
getdata();
};
// 页码切换
const currentChange = (value: number) => {
console.log(value);
apiData.pager.page = value
getdata()
}
// 复制链接
const copy = async(row: ProjectApi, env?: string) => {
let text = `${config.baseUrl.pro}/glsxAdmin/config?moduleUrl=${row.url}`
if (env) {
text += `&env=${row.baseUrl}`
}
copyText(text)
}
const copyText = (e: any) => {
//创建一个input框
const input = document.createElement("input");
//将指定的DOM节点添加到body的末尾
document.body.appendChild(input);
//设置input框的value值为直播地址
input.setAttribute("value", e);
//选取文本域中的内容
input.select();
//copy的意思是拷贝当前选中内容到剪贴板
//document.execCommand()方法操纵可编辑内容区域的元素
//返回值为一个Boolean,如果是 false 则表示操作不被支持或未被启用
if (document.execCommand("copy")) {
document.execCommand("copy");
}
//删除这个节点
document.body.removeChild(input);
}
getdata();
return {
apiData,
editorRow,
deleteRow,
addFn,
disabled,
search,
currentChange,
copy
};
},
};
</script>
<style lang="scss" scoped>
.api-list {
padding: 40px 20px 20px;
h3 {
margin-bottom: 20px;
text-align: center;
}
}
.search-input {
width: 300px;
margin-bottom: 20px;
}
.search-button {
margin-left: 20px;
}
.mt-4 {
margin-top: 10px;
}
</style>