index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <!-- <el-form-item label="所属系统" >
  5. <el-select
  6. v-model="queryParams.name"
  7. placeholder="请选择所属系统"
  8. @change="select"
  9. style="width: 150px"
  10. clearable
  11. >
  12. <el-option
  13. v-for="(item, index) in SubsystemList"
  14. :key="index"
  15. :label="item.label"
  16. :value="item.value"
  17. >
  18. </el-option>
  19. </el-select>
  20. </el-form-item> -->
  21. <el-form-item label="接口名称">
  22. <el-input
  23. v-model.trim="queryParams.name"
  24. placeholder="请输入接口名称"
  25. clearable
  26. size="small"
  27. style="width: 140px"
  28. @keyup.enter.native="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  33. <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  34. <el-button
  35. type="primary"
  36. plain
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. >新增</el-button>
  41. <!-- <el-button
  42. type="warning"
  43. plain
  44. icon="el-icon-download"
  45. size="mini"
  46. :loading="exportLoading"
  47. @click="handleExport"
  48. >导出</el-button> -->
  49. </el-form-item>
  50. </el-form>
  51. <el-table v-loading="loading" :data="adminList" @selection-change="handleSelectionChange" height="calc(100vh - 30vh)">
  52. <!-- <el-table-column label="系统名称" align="center" prop="name" show-overflow-tooltip /> -->
  53. <el-table-column label="接口名称" align="center" prop="name" show-overflow-tooltip />
  54. <el-table-column label="接口链接" align="center" prop="url" show-overflow-tooltip />
  55. <el-table-column label="状态" align="center" >
  56. <template slot-scope="scope">
  57. <el-switch
  58. v-model="scope.row.enableFlag"
  59. active-color="#13ce66"
  60. inactive-color="#ff4949"
  61. @change="handleStatusChange(scope.row)"
  62. ></el-switch>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip />
  66. <el-table-column label="操作" align="center">
  67. <template slot-scope="scope">
  68. <el-button
  69. size="mini"
  70. type="primary"
  71. icon="el-icon-edit"
  72. @click="handleUpdate(scope.row)"
  73. >编辑</el-button>
  74. <el-button
  75. size="mini"
  76. type="danger"
  77. icon="el-icon-delete"
  78. @click="handleDelete(scope.row)"
  79. >删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <pagination
  84. v-show="total>0"
  85. :total="total"
  86. :page.sync="queryParams.current"
  87. :limit.sync="queryParams.size"
  88. @pagination="getList"
  89. />
  90. <!-- 添加或修改参数配置对话框 -->
  91. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :before-close="cancel" :close-on-click-modal="false">
  92. <el-form ref="form" :model="form" :rules="rules" label-width="120px" >
  93. <el-row :gutter="20">
  94. <!-- <el-col :span="16">
  95. <el-form-item label="所属系统" prop="name1">
  96. <el-select
  97. v-model="form.data1"
  98. placeholder="请选择所属系统"
  99. @change="select"
  100. clearable
  101. style="width:245px"
  102. >
  103. <el-option
  104. v-for="(item, index) in SubsystemList"
  105. :key="index"
  106. :label="item.label"
  107. :value="item.value"
  108. >
  109. </el-option>
  110. </el-select>
  111. </el-form-item>
  112. </el-col> -->
  113. <el-col :span="16" >
  114. <el-form-item label="接口名称" prop="name" >
  115. <el-input v-model.trim="form.name" placeholder="请输入接口名称" @input="onInput" maxlength="30" show-word-limit />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="24">
  119. <el-form-item label="接口链接" prop="url">
  120. <el-input v-model.trim="form.url" placeholder="请输入接口连接" @input="onInput" maxlength="30" show-word-limit />
  121. </el-form-item>
  122. </el-col>
  123. <!-- <el-col :span="12">
  124. <el-form-item label="接口类型" prop="data6">
  125. <el-switch
  126. v-model="value1"
  127. active-color="调用"
  128. inactive-color="回调"
  129. ></el-switch>
  130. </el-form-item>
  131. </el-col> -->
  132. <el-col :span="12">
  133. <el-form-item label="接口状态" prop="enableFlag">
  134. <el-switch
  135. v-model="enableFlag"
  136. ></el-switch>
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="16">
  140. <el-form-item label="参数结构" prop="params">
  141. <el-input type="textarea" :rows="5" v-model.trim="form.params" placeholder="请输入参数结构" @input="onInput" maxlength="30" show-word-limit />
  142. </el-form-item>
  143. </el-col>
  144. </el-row>
  145. </el-form>
  146. <div slot="footer" class="dialog-footer">
  147. <el-button type="primary" @click="submitForm" v-if="!loading">确 定</el-button>
  148. <el-button :loading="loading" type="primary" @click="submitForm" v-else>提交中...</el-button>
  149. <el-button @click="cancel">取 消</el-button>
  150. </div>
  151. </el-dialog>
  152. <!-- 导出-->
  153. <a href="" download="" id="xz" style="position: absolute;z-index: -1;opacity: 0;"></a>
  154. </div>
  155. </template>
  156. <script>
  157. import { addZkSystemDoc, delZkSystemDoc, updataZkSystemDoc, getZkSystemDoc, exportZkSystemDoc } from "@/api/business/Middleware/functionalInterface";
  158. import { BASEPATH } from "@/assets/js/common.js";
  159. export default {
  160. name: "admin",
  161. data() {
  162. return {
  163. // 遮罩层
  164. loading: false,
  165. // 导出遮罩层
  166. exportLoading: false,
  167. // 显示搜索条件
  168. showSearch: true,
  169. // 总条数
  170. total: 0,
  171. // 参数表格数据
  172. adminList: [],
  173. SubsystemList:[
  174. {value:"安防",label:"1"},
  175. {value:"充值",label:"2"},
  176. ],
  177. // 弹出层标题
  178. title: "",
  179. // 是否显示弹出层
  180. open: false,
  181. // 查询参数
  182. queryParams: {
  183. current: 1,
  184. size: 20,
  185. name:undefined
  186. },
  187. // 表单参数
  188. form: {},
  189. // 表单校验
  190. rules: {
  191. name: [
  192. { required: true, message: "接口名称不能为空", trigger: "blur" }
  193. ],
  194. url: [
  195. { required: true, message: "接口链接不能为空", trigger: "blur" }
  196. ],
  197. },
  198. enableFlag:undefined
  199. };
  200. },
  201. created() {
  202. this.getList();
  203. },
  204. methods: {
  205. //强制el-input刷新
  206. onInput(){
  207. this.$forceUpdate();
  208. },
  209. /** 查询参数列表 */
  210. getList() {
  211. this.loading = true;
  212. getZkSystemDoc(this.queryParams).then(response => {
  213. this.adminList = response.data.records;
  214. this.total = response.data.total;
  215. this.loading = false;
  216. }
  217. );
  218. },
  219. // 取消按钮
  220. cancel() {
  221. this.open = false;
  222. this.reset();
  223. },
  224. // 表单重置
  225. reset() {
  226. this.form = {};
  227. this.resetForm("form");
  228. },
  229. /** 搜索按钮操作 */
  230. handleQuery() {
  231. this.queryParams.current = 1;
  232. this.getList();
  233. },
  234. /** 重置按钮操作 */
  235. resetQuery() {
  236. this.resetForm("queryForm");
  237. this.queryParams.name = undefined
  238. this.handleQuery();
  239. },
  240. /** 新增按钮操作 */
  241. handleAdd() {
  242. this.reset();
  243. this.open = true;
  244. this.title = "添加参数";
  245. },
  246. /** 修改按钮操作 */
  247. handleUpdate(row) {
  248. this.open = true;
  249. this.form = JSON.parse(JSON.stringify(row))
  250. this.enableFlag = row.enableFlag
  251. this.title = "修改参数";
  252. },
  253. /** 提交按钮 */
  254. submitForm(row) {
  255. this.$refs["form"].validate(valid => {
  256. if (valid) {
  257. this.form.enableFlag = this.enableFlag
  258. this.form.systemId =1
  259. this.loading = true
  260. if (this.form.id != undefined) {
  261. updataZkSystemDoc(this.form).then(response => {
  262. this.loading = false
  263. this.msgSuccess("修改成功");
  264. this.open = false;
  265. this.getList();
  266. }).catch(()=>{
  267. this.loading = false,
  268. this.open = false
  269. })
  270. } else {
  271. addZkSystemDoc(this.form).then(response => {
  272. this.loading = false
  273. this.msgSuccess("新增成功");
  274. this.open = false;
  275. this.getList();
  276. }).catch(()=>{
  277. this.loading = false,
  278. this.open = false
  279. })
  280. }
  281. }
  282. });
  283. },
  284. handleStatusChange(row){
  285. // 用户状态修改
  286. let text = row.enableFlag === true ? "启用" : "停用";
  287. this.$confirm('确认要"' + text + '""' + row.name + '"接口吗?', "警告", {
  288. confirmButtonText: "确定",
  289. cancelButtonText: "取消",
  290. type: "warning"
  291. }).then(function() {
  292. updataZkSystemDoc(row).then(response => {
  293. }).catch(()=>{
  294. })
  295. }).then(() => {
  296. this.msgSuccess(text + "成功");
  297. }).catch(function() {
  298. row.status = row.status === "0" ? "1" : "0";
  299. });
  300. },
  301. /** 删除按钮操作 */
  302. handleDelete(row) {
  303. const ids = row.id
  304. this.$confirm('是否确认删除', "警告", {
  305. confirmButtonText: "确定",
  306. cancelButtonText: "取消",
  307. type: "warning"
  308. }).then(function() {
  309. return delZkSystemDoc(ids);
  310. }).then(() => {
  311. this.getList();
  312. this.msgSuccess("删除成功");
  313. }).catch(() => {});
  314. },
  315. /** 导出按钮操作 */
  316. handleExport() {
  317. let queryParams = {...this.queryParams};
  318. delete queryParams.current
  319. delete queryParams.size
  320. this.exportLoading = true;
  321. exportZkSystemDoc(queryParams).then(response =>{
  322. this.exportLoading = false;
  323. document.getElementById("xz").href = BASEPATH() + response.data
  324. document.getElementById("xz").download = response.data
  325. document.getElementById("xz").click()
  326. }).catch(()=>{
  327. this.exportLoading = false;
  328. })
  329. }
  330. }
  331. };
  332. </script>
  333. <style>
  334. .el-upload{
  335. border: 1px dashed #ccc !important;
  336. width:100px;
  337. height:100px;
  338. }
  339. .avatar-uploader .el-upload {
  340. border: 1px dashed #ccc !important;
  341. border-radius: 6px;
  342. cursor: pointer;
  343. position: relative;
  344. overflow: hidden;
  345. }
  346. .avatar-uploader .el-upload:hover {
  347. border-color: #409EFF;
  348. }
  349. .avatar-uploader-icon {
  350. font-size: 28px;
  351. color: #8c939d;
  352. width: 50px;
  353. height: 50px;
  354. line-height: 100px;
  355. text-align: center;
  356. }
  357. .avatar {
  358. width: 178px;
  359. height: 178px;
  360. display: block;
  361. }
  362. </style>