examIpLimit.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. <template>
  2. <section class="content">
  3. <LinkTitlesCustom :current-paths="['考试管理', '考试信息', 'ip访问限制']" />
  4. <div class="box box-info">
  5. <!-- 正文信息 -->
  6. <div class="box-body">
  7. <el-form
  8. ref="formSearch"
  9. :model="formSearch"
  10. :inline="true"
  11. label-width="70px"
  12. >
  13. <el-form-item label="考试名称">
  14. <el-input
  15. v-model="formSearch.examName"
  16. class="input"
  17. :disabled="true"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item label="考试类型">
  21. <el-input
  22. v-model="formSearch.examType"
  23. class="input"
  24. :disabled="true"
  25. ></el-input>
  26. </el-form-item>
  27. <el-form-item label="ip">
  28. <el-input
  29. v-model="formSearch.ip"
  30. placeholder="请输入ip"
  31. class="input"
  32. ></el-input>
  33. </el-form-item>
  34. <el-form-item label="限制类型">
  35. <el-select v-model="formSearch.limitType" class="input">
  36. <el-option label="未选择" value=""></el-option>
  37. <el-option label="允许访问" value="0"></el-option>
  38. <el-option label="禁止访问" value="1"></el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item class="d-block">
  42. <el-button
  43. size="small"
  44. type="primary"
  45. icon="el-icon-search"
  46. @click="resetPageAndSearchForm"
  47. >查询</el-button
  48. >
  49. <el-button
  50. size="small"
  51. icon="el-icon-refresh"
  52. @click="resetSearchForm"
  53. >重置</el-button
  54. >
  55. <el-button
  56. size="small"
  57. type="primary"
  58. icon="el-icon-arrow-left"
  59. @click="back"
  60. >返回</el-button
  61. >
  62. </el-form-item>
  63. </el-form>
  64. <div class="block-seperator"></div>
  65. <el-button
  66. size="small"
  67. type="primary"
  68. icon="el-icon-plus"
  69. @click="openAddingDialog"
  70. >新增</el-button
  71. >
  72. <el-button
  73. size="small"
  74. type="primary"
  75. icon="el-icon-edit"
  76. :disabled="noBatchSelected"
  77. @click="editIpLimitType"
  78. >类型设置</el-button
  79. >
  80. <el-button
  81. size="small"
  82. type="primary"
  83. icon="el-icon-edit"
  84. @click="editIpLimitProperty"
  85. >控制设置</el-button
  86. >
  87. <el-button
  88. size="small"
  89. type="primary"
  90. icon="el-icon-upload2"
  91. @click="batchImport"
  92. >批量导入</el-button
  93. >
  94. <el-button
  95. size="small"
  96. type="primary"
  97. icon="el-icon-download"
  98. @click="batchExport"
  99. >批量导出</el-button
  100. >
  101. <el-button
  102. size="small"
  103. type="danger"
  104. icon="el-icon-delete"
  105. :disabled="noBatchSelected"
  106. @click="batchDelete"
  107. >批量删除</el-button
  108. >
  109. <el-button
  110. size="small"
  111. type="danger"
  112. icon="el-icon-delete"
  113. @click="allDelete"
  114. >全部删除</el-button
  115. >
  116. <div style="width: 100%; margin-bottom: 10px"></div>
  117. <!-- 页面列表 -->
  118. <el-table
  119. :data="tableData"
  120. border
  121. style="width: 100%; text-align: center"
  122. @selection-change="selectChange"
  123. >
  124. <el-table-column type="selection" width="50"></el-table-column>
  125. <el-table-column
  126. prop="id"
  127. width="100"
  128. label="ID"
  129. sortable
  130. ></el-table-column>
  131. <el-table-column label="IP地址">
  132. <span slot-scope="scope" v-html="scope.row.ip"></span>
  133. </el-table-column>
  134. <el-table-column
  135. prop="limitType"
  136. label="限制类型"
  137. sortable
  138. ></el-table-column>
  139. <el-table-column
  140. width="180"
  141. prop="creationTime"
  142. label="创建时间"
  143. ></el-table-column>
  144. <el-table-column
  145. width="180"
  146. prop="updateTime"
  147. label="修改时间"
  148. ></el-table-column>
  149. <el-table-column label="操作" width="300">
  150. <div slot-scope="scope">
  151. <el-button
  152. size="mini"
  153. type="primary"
  154. icon="el-icon-edit"
  155. @click="editIpLimit(scope.row)"
  156. >修改</el-button
  157. >
  158. <el-button
  159. size="mini"
  160. type="danger"
  161. icon="el-icon-delete"
  162. @click="deleteIpLimit(scope.row)"
  163. >删除</el-button
  164. >
  165. <el-button
  166. size="mini"
  167. type="primary"
  168. icon="el-icon-edit"
  169. @click="editIpLimitType(scope.row)"
  170. >切换类型</el-button
  171. >
  172. </div>
  173. </el-table-column>
  174. </el-table>
  175. <div class="page pull-right">
  176. <el-pagination
  177. :current-page="currentPage"
  178. :page-size="pageSize"
  179. :page-sizes="[10, 20, 50, 100, 200, 300]"
  180. layout="total, sizes, prev, pager, next, jumper"
  181. :total="total"
  182. @current-change="handleCurrentChange"
  183. @size-change="handleSizeChange"
  184. ></el-pagination>
  185. </div>
  186. <!-- 新增弹出窗口 -->
  187. <el-dialog
  188. title="IP限制信息页面"
  189. :visible.sync="addingIpLimitDialog"
  190. width="650px"
  191. @close="closeAddIpLimitDialog"
  192. >
  193. <el-form
  194. ref="addIpLimitForm"
  195. :rules="rules"
  196. :model="examIpLimitForm"
  197. :inline="true"
  198. label-width="85px"
  199. class="editForm"
  200. >
  201. <el-form-item label="ip" prop="ip">
  202. <el-input
  203. v-model="examIpLimitForm.ip"
  204. class="input"
  205. auto-complete="off"
  206. :disabled="!showIpColumn"
  207. maxlength="20"
  208. ></el-input>
  209. </el-form-item>
  210. <el-form-item label="限制类型" prop="limitType">
  211. <el-select
  212. v-model="examIpLimitForm.limitType"
  213. class="input"
  214. auto-complete="off"
  215. maxlength="20"
  216. >
  217. <el-option
  218. v-for="item in limitTypeList"
  219. :key="item.id"
  220. :label="item.label"
  221. :value="item.id"
  222. ></el-option>
  223. </el-select>
  224. </el-form-item>
  225. </el-form>
  226. <div style="text-align: center">
  227. <el-button type="primary" @click="addIpLimit">确 定</el-button>
  228. <el-button @click="closeAddIpLimitDialog">取 消</el-button>
  229. </div>
  230. </el-dialog>
  231. <!-- 切换类型弹出窗口 -->
  232. <el-dialog
  233. title="类型切换页面"
  234. :visible.sync="editIpLimitTypeDialog"
  235. width="650px"
  236. @close="closeEditIpLimitTypeDialog"
  237. >
  238. <el-form
  239. ref="addIpLimitTypeForm"
  240. :rules="rules"
  241. :model="examIpLimitTypeForm"
  242. :inline="true"
  243. label-width="85px"
  244. style="text-align: center"
  245. class="editForm"
  246. >
  247. <el-form-item label="限制类型" prop="limitType">
  248. <el-select
  249. v-model="examIpLimitTypeForm.limitType"
  250. class="input"
  251. auto-complete="off"
  252. maxlength="20"
  253. >
  254. <el-option
  255. v-for="item in limitTypeList"
  256. :key="item.id"
  257. :label="item.label"
  258. :value="item.id"
  259. ></el-option>
  260. </el-select>
  261. </el-form-item>
  262. </el-form>
  263. <div style="text-align: center">
  264. <el-button type="primary" @click="addIpLimitType">确 定</el-button>
  265. <el-button @click="closeEditIpLimitTypeDialog">取 消</el-button>
  266. </div>
  267. </el-dialog>
  268. <!-- 控制修改弹出窗口 -->
  269. <el-dialog
  270. title="控制修改页面"
  271. :visible.sync="editIpLimitPropertyDialog"
  272. width="650px"
  273. @close="closeEditIpLimitPropertyDialog"
  274. >
  275. <el-form
  276. ref="addIpLimitPropertyForm"
  277. :rules="rules"
  278. :model="examIpLimitPropertyForm"
  279. :inline="true"
  280. label-width="85px"
  281. class="editForm"
  282. >
  283. <el-form-item label="整体控制" prop="totalLimit">
  284. <el-select
  285. v-model="examIpLimitPropertyForm.totalLimit"
  286. class="input"
  287. auto-complete="off"
  288. maxlength="20"
  289. >
  290. <el-option
  291. v-for="item in totalList"
  292. :key="item.id"
  293. :label="item.label"
  294. :value="item.id"
  295. ></el-option>
  296. </el-select>
  297. </el-form-item>
  298. <el-form-item v-show="false" label="学习中心" prop="centerLimit">
  299. <el-select
  300. v-model="examIpLimitPropertyForm.centerLimit"
  301. class="input"
  302. auto-complete="off"
  303. maxlength="20"
  304. >
  305. <el-option
  306. v-for="item in centerList"
  307. :key="item.id"
  308. :label="item.label"
  309. :value="item.id"
  310. ></el-option>
  311. </el-select>
  312. </el-form-item>
  313. </el-form>
  314. <div style="text-align: center">
  315. <el-button type="primary" @click="addIpLimitProperty"
  316. >确 定</el-button
  317. >
  318. <el-button @click="closeEditIpLimitPropertyDialog">取 消</el-button>
  319. </div>
  320. </el-dialog>
  321. <!-- 导入弹窗 -->
  322. <el-dialog
  323. title="Ip限制信息导入页"
  324. size="tiny"
  325. :visible.sync="ipLimitImportDialog"
  326. >
  327. <el-form ref="ipLimitImportForm" :model="ipLimitImportForm">
  328. <el-row>
  329. <el-form-item style="margin-left: 30px">
  330. <el-upload
  331. ref="upload"
  332. class="form_left"
  333. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  334. :action="uploadAction"
  335. :headers="uploadHeaders"
  336. :data="uploadData"
  337. :on-success="uploadSuccess"
  338. :on-error="uploadError"
  339. :file-list="fileList"
  340. :auto-upload="false"
  341. :multiple="false"
  342. >
  343. <el-button
  344. slot="trigger"
  345. size="small"
  346. type="primary"
  347. icon="el-icon-search"
  348. >选择文件</el-button
  349. >
  350. <el-button
  351. size="small"
  352. style="margin-left: 10px"
  353. type="primary"
  354. icon="el-icon-check"
  355. @click="submitUpload"
  356. >确认上传
  357. </el-button>
  358. <el-button
  359. size="small"
  360. style="margin-left: 10px"
  361. type="primary"
  362. icon="el-icon-refresh"
  363. @click="removeFile"
  364. >清空文件
  365. </el-button>
  366. <el-button
  367. size="small"
  368. type="primary"
  369. icon="el-icon-download"
  370. @click="exportFile"
  371. >下载模板
  372. </el-button>
  373. <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
  374. </el-upload>
  375. </el-form-item>
  376. </el-row>
  377. </el-form>
  378. </el-dialog>
  379. <!-- 导入错误信息列表 -->
  380. <el-dialog title="错误提示" :visible.sync="errDialog">
  381. <div
  382. v-for="errMessage in errMessages"
  383. :key="errMessage.lineNum"
  384. class="text-danger"
  385. >
  386. 第{{ errMessage.lineNum }}行:{{ errMessage.msg }}
  387. </div>
  388. <span slot="footer" class="dialog-footer">
  389. <el-button @click="errDialog = false">确定</el-button>
  390. </span>
  391. </el-dialog>
  392. </div>
  393. </div>
  394. </section>
  395. </template>
  396. <script>
  397. import { EXAM_WORK_API } from "@/constants/constants.js";
  398. import { mapState } from "vuex";
  399. export default {
  400. data() {
  401. return {
  402. limitTypeList: [
  403. {
  404. id: 0,
  405. label: "允许访问",
  406. },
  407. {
  408. id: 1,
  409. label: "禁止访问",
  410. },
  411. ],
  412. centerList: [
  413. {
  414. id: false,
  415. label: "关闭",
  416. },
  417. {
  418. id: true,
  419. label: "开启",
  420. },
  421. ],
  422. totalList: [
  423. {
  424. id: false,
  425. label: "全部黑名单模式",
  426. },
  427. {
  428. id: true,
  429. label: "全部白名单模式",
  430. },
  431. ],
  432. showIpColumn: true,
  433. button: {},
  434. ipLimitImportDialog: false,
  435. editIpLimitPropertyDialog: false,
  436. examIpLimitForm: {
  437. id: "",
  438. ip: "",
  439. examId: "",
  440. limitType: "",
  441. },
  442. examIpLimitTypeForm: {
  443. id: "",
  444. examId: null,
  445. limitType: "",
  446. },
  447. examIpLimitPropertyForm: {
  448. totalLimit: "",
  449. centerLimit: "",
  450. },
  451. formSearch: {
  452. examId: "",
  453. examName: "",
  454. examType: "",
  455. ip: "",
  456. limitType: "",
  457. },
  458. selectedIpIds: [],
  459. tableData: [],
  460. currentPage: 1,
  461. pageSize: 10,
  462. total: 10,
  463. rules: {
  464. ip: [
  465. { required: true, message: "Ip不能为空!", trigger: "change" },
  466. {
  467. pattern:
  468. /^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9/*]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9/*]))$/,
  469. message: "请输入正确的ip格式",
  470. },
  471. ],
  472. limitType: [
  473. { required: true, message: "限制类型不能为空!", trigger: "change" },
  474. ],
  475. },
  476. addingIpLimitDialog: false,
  477. editIpLimitTypeDialog: false,
  478. ipLimitImportForm: {
  479. examId: "",
  480. },
  481. uploadAction: EXAM_WORK_API + "/exam/ipLimited/import",
  482. uploadData: {},
  483. fileLoading: false,
  484. errDialog: false,
  485. fileList: [],
  486. uploadHeaders: {},
  487. };
  488. },
  489. computed: {
  490. ...mapState({ user: (state) => state.user }),
  491. stuIds() {
  492. var ipIds = "";
  493. for (let ipId of this.selectedIpIds) {
  494. if (!ipIds) {
  495. ipIds += ipId;
  496. } else {
  497. ipIds += "," + ipId;
  498. }
  499. }
  500. return ipIds;
  501. },
  502. noBatchSelected() {
  503. return this.selectedIpIds.length === 0;
  504. },
  505. isSuperAdmin() {
  506. return this.user.roleList.some((role) => role.roleCode == "SUPER_ADMIN");
  507. },
  508. },
  509. created() {
  510. this.init();
  511. this.uploadHeaders = {
  512. key: this.user.key,
  513. token: this.user.token,
  514. };
  515. this.formSearch.examId = this.$route.params.id;
  516. this.formSearch.examType = this.$route.params.examTypeName;
  517. this.formSearch.examName = this.$route.params.examName;
  518. },
  519. methods: {
  520. //新增
  521. openAddingDialog() {
  522. if (this.$refs["examIpLimitForm"]) {
  523. this.$refs["examIpLimitForm"].resetFields();
  524. }
  525. this.examIpLimitForm.id = null;
  526. this.examIpLimitForm.ip = null;
  527. this.examIpLimitForm.limitType = null;
  528. this.addingIpLimitDialog = true;
  529. this.showIpColumn = true;
  530. },
  531. closeAddIpLimitDialog() {
  532. this.addingIpLimitDialog = false;
  533. },
  534. closeEditIpLimitTypeDialog() {
  535. this.editIpLimitTypeDialog = false;
  536. },
  537. closeEditIpLimitPropertyDialog() {
  538. this.editIpLimitPropertyDialog = false;
  539. },
  540. //新增信息
  541. addIpLimit() {
  542. var url = EXAM_WORK_API + "/exam/ipLimited";
  543. this.examIpLimitForm.examId = this.formSearch.examId;
  544. this.$refs.addIpLimitForm.validate((valid) => {
  545. if (valid) {
  546. this.$httpWithMsg.post(url, this.examIpLimitForm).then(() => {
  547. this.$notify({
  548. type: "success",
  549. message: "保存成功",
  550. });
  551. this.addingIpLimitDialog = false;
  552. this.searchForm();
  553. });
  554. } else {
  555. return false;
  556. }
  557. });
  558. },
  559. addIpLimitType() {
  560. var ids = this.selectedIpIds;
  561. var id = this.examIpLimitTypeForm.id;
  562. var url = EXAM_WORK_API + "/exam/ipLimited";
  563. if (!id) {
  564. url = url + "?ids=" + ids;
  565. }
  566. this.examIpLimitTypeForm.examId = this.formSearch.examId;
  567. this.$refs.addIpLimitTypeForm.validate((valid) => {
  568. if (valid) {
  569. this.$httpWithMsg.post(url, this.examIpLimitTypeForm).then(() => {
  570. this.$notify({
  571. type: "success",
  572. message: "保存成功",
  573. });
  574. this.editIpLimitTypeDialog = false;
  575. this.searchForm();
  576. });
  577. } else {
  578. return false;
  579. }
  580. });
  581. },
  582. addIpLimitProperty() {
  583. var url =
  584. EXAM_WORK_API + "/exam/ipLimited/property/" + this.formSearch.examId;
  585. this.$refs.addIpLimitPropertyForm.validate((valid) => {
  586. if (valid) {
  587. this.$httpWithMsg.post(url, this.examIpLimitPropertyForm).then(() => {
  588. this.$notify({
  589. type: "success",
  590. message: "保存成功",
  591. });
  592. this.editIpLimitPropertyDialog = false;
  593. this.searchForm();
  594. });
  595. } else {
  596. return false;
  597. }
  598. });
  599. },
  600. editIpLimit(row) {
  601. if (this.$refs.examIpLimitForm) {
  602. this.$refs.examIpLimitForm.resetFields();
  603. }
  604. this.examIpLimitForm.id = row.id;
  605. this.examIpLimitForm.ip = row.ip;
  606. this.examIpLimitForm.limitType = this.getLimitType(row.limitType);
  607. this.addingIpLimitDialog = true;
  608. this.showIpColumn = true;
  609. },
  610. getLimitType(type) {
  611. if (type === "允许访问") {
  612. return 0;
  613. } else if (type === "禁止访问") {
  614. return 1;
  615. }
  616. return null;
  617. },
  618. batchDelete() {
  619. this.$confirm("确定删除所选数据吗?", "提示", {
  620. confirmButtonText: "确定",
  621. cancelButtonText: "取消",
  622. type: "error",
  623. }).then(() => {
  624. let url = EXAM_WORK_API + "/exam/ipLimited/" + this.selectedIpIds;
  625. this.deleteIp(url);
  626. });
  627. },
  628. allDelete() {
  629. this.$confirm("确定删除该考试下的所有Ip限制吗?", "提示", {
  630. confirmButtonText: "确定",
  631. cancelButtonText: "取消",
  632. type: "error",
  633. }).then(() => {
  634. let url =
  635. EXAM_WORK_API + "/exam/ipLimited/all/" + this.formSearch.examId;
  636. this.deleteIp(url);
  637. });
  638. },
  639. deleteIpLimit(row) {
  640. this.$confirm("确定删除当前数据吗?", "提示", {
  641. confirmButtonText: "确定",
  642. cancelButtonText: "取消",
  643. type: "error",
  644. }).then(() => {
  645. let url = EXAM_WORK_API + "/exam/ipLimited/" + row.id;
  646. this.deleteIp(url);
  647. });
  648. },
  649. editIpLimitType(row) {
  650. if (this.$refs.addIpLimitTypeForm) {
  651. this.$refs.addIpLimitTypeForm.resetFields();
  652. }
  653. if (row) {
  654. this.examIpLimitTypeForm.id = row.id;
  655. this.examIpLimitTypeForm.limitType = row.limitType;
  656. } else {
  657. this.examIpLimitTypeForm.id = null;
  658. this.examIpLimitTypeForm.limitType = null;
  659. }
  660. this.editIpLimitTypeDialog = true;
  661. },
  662. editIpLimitProperty() {
  663. if (this.$refs.addIpLimitPropertyForm) {
  664. this.$refs.addIpLimitPropertyForm.resetFields();
  665. }
  666. var url =
  667. EXAM_WORK_API + "/exam/ipLimited/property/" + this.formSearch.examId;
  668. this.$httpWithMsg.get(url).then((response) => {
  669. this.examIpLimitPropertyForm.totalLimit = response.data.totalLimit;
  670. this.examIpLimitPropertyForm.centerLimit = response.data.centerLimit;
  671. });
  672. this.editIpLimitPropertyDialog = true;
  673. },
  674. deleteIp(url) {
  675. this.$httpWithMsg.delete(url).then(() => {
  676. this.$notify({
  677. type: "success",
  678. message: "操作成功!",
  679. });
  680. this.searchForm();
  681. });
  682. },
  683. selectChange(row) {
  684. this.selectedIpIds = [];
  685. row.forEach((element) => {
  686. this.selectedIpIds.push(element.id);
  687. });
  688. },
  689. handleCurrentChange(val) {
  690. this.currentPage = val;
  691. this.searchForm();
  692. },
  693. handleSizeChange(val) {
  694. this.pageSize = val;
  695. this.searchForm();
  696. },
  697. resetSearchForm() {
  698. this.formSearch.ip = "";
  699. this.formSearch.limitType = "";
  700. },
  701. resetPageAndSearchForm() {
  702. this.currentPage = 1;
  703. this.searchForm();
  704. },
  705. //查询方法
  706. searchForm() {
  707. this.formSearch.examId = this.$route.params.id;
  708. var param = new URLSearchParams(this.formSearch);
  709. var url =
  710. EXAM_WORK_API +
  711. "/exam/ipLimited/page/" +
  712. (this.currentPage - 1) +
  713. "/" +
  714. this.pageSize +
  715. "?" +
  716. param;
  717. this.$httpWithMsg.get(url).then((response) => {
  718. this.tableData = response.data.list;
  719. this.total = response.data.total;
  720. });
  721. },
  722. batchExport() {
  723. var param =
  724. new URLSearchParams(this.formSearch) +
  725. "&$key=" +
  726. this.user.key +
  727. "&$token=" +
  728. this.user.token;
  729. var url = EXAM_WORK_API + "/exam/ipLimited/export?" + param;
  730. window.open(url);
  731. },
  732. initUpload() {
  733. if (this.$refs.ipLimitImportForm) {
  734. this.$refs.ipLimitImportForm.resetFields();
  735. }
  736. this.fileList = [];
  737. this.uploadAction =
  738. EXAM_WORK_API + "/exam/ipLimited/import/" + this.formSearch.examId;
  739. },
  740. batchImport() {
  741. this.ipLimitImportDialog = true;
  742. this.initUpload();
  743. },
  744. uploadSuccess(response) {
  745. if (!response.hasError) {
  746. this.$notify({
  747. message: "上传成功",
  748. type: "success",
  749. });
  750. this.fileLoading = false;
  751. this.ipLimitImportDialog = false;
  752. this.searchForm();
  753. } else {
  754. this.fileLoading = false;
  755. this.ipLimitImportDialog = false;
  756. this.errMessages = response.failRecords;
  757. this.errDialog = true;
  758. }
  759. },
  760. uploadError(response) {
  761. console.log("uploadError");
  762. var json = JSON.parse(response.message);
  763. if (response.status == 500) {
  764. this.$notify({
  765. message: json.desc,
  766. type: "error",
  767. });
  768. }
  769. this.fileLoading = false;
  770. },
  771. //确定上传
  772. submitUpload() {
  773. if (!this.checkUpload()) {
  774. return false;
  775. }
  776. this.$refs.upload.submit();
  777. this.fileLoading = true;
  778. },
  779. checkUpload() {
  780. var fileList = this.$refs.upload.uploadFiles;
  781. if (fileList.length == 0) {
  782. this.$notify({
  783. message: "上传文件不能为空",
  784. type: "error",
  785. });
  786. return false;
  787. }
  788. if (fileList.length > 1) {
  789. this.$notify({
  790. message: "每次只能上传一个文件",
  791. type: "error",
  792. });
  793. return false;
  794. }
  795. for (let file of fileList) {
  796. if (!file.name.endsWith(".xlsx")) {
  797. this.$notify({
  798. message: "上传文件必须为xlsx格式",
  799. type: "error",
  800. });
  801. this.initUpload();
  802. return false;
  803. }
  804. }
  805. return true;
  806. },
  807. //清空文件
  808. removeFile() {
  809. this.$refs.upload.clearFiles();
  810. },
  811. //下载模板
  812. exportFile() {
  813. window.location.href =
  814. "/api/ecs_exam_work/exam/ipLimited/downloadTemplate?$key=" +
  815. this.user.key +
  816. "&$token=" +
  817. this.user.token;
  818. },
  819. back() {
  820. this.$router.push({ path: "/examwork/examInfo" });
  821. },
  822. async init() {
  823. this.searchForm();
  824. },
  825. },
  826. };
  827. </script>
  828. <style scoped>
  829. .input {
  830. width: 180px;
  831. }
  832. </style>