ExportTemplate.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <section class="content">
  3. <div class="box-body">
  4. <!-- 表单 -->
  5. <el-form
  6. :inline="true"
  7. :model="formSearch"
  8. label-width="70px"
  9. label-position="right"
  10. >
  11. <el-row>
  12. <el-col :span="6">
  13. <el-form-item v-if="isSuperAdmin" label="学校">
  14. <el-select
  15. v-model="formSearch.rootOrgId"
  16. clearable
  17. filterable
  18. placeholder="请选择"
  19. class="search_width"
  20. size="small"
  21. >
  22. <el-option
  23. v-for="item in rootOrgList"
  24. :key="item.id"
  25. :label="item.name"
  26. :value="item.id"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="6">
  32. <el-form-item label="模板名称">
  33. <el-input
  34. v-model="formSearch.fileName"
  35. placeholder="请输入模板名称"
  36. class="search_width"
  37. size="small"
  38. ></el-input>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="6">
  42. <el-form-item label="模板类型" prop="type" class="form-item">
  43. <el-select
  44. v-model="formSearch.type"
  45. class="search_width"
  46. :clearable="true"
  47. size="small"
  48. >
  49. <el-option label="试卷导出" value="PAPER_EXPORT"> </el-option>
  50. <el-option label="答案导出" value="ANWSER_EXPORT"> </el-option>
  51. <el-option label="离线试卷" value="OUTLINE_PAPER_EXPORT">
  52. </el-option>
  53. <el-option label="试卷预览" value="PAPER_VIEW"> </el-option>
  54. <el-option label="答案预览" value="ANWSER_VIEW"> </el-option>
  55. </el-select>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="6">
  59. <div class="search_down">
  60. <el-button
  61. size="small"
  62. type="primary"
  63. icon="el-icon-search"
  64. @click="handleSearchBtn"
  65. >
  66. 查询
  67. </el-button>
  68. <el-button
  69. size="small"
  70. type="primary"
  71. icon="el-icon-plus"
  72. @click="addFile"
  73. >
  74. 新增
  75. </el-button>
  76. <el-button
  77. size="small"
  78. type="primary"
  79. icon="el-icon-edit"
  80. @click="operConfig"
  81. >
  82. 配置
  83. </el-button>
  84. </div>
  85. </el-col>
  86. </el-row>
  87. </el-form>
  88. <div class="block-seperator"></div>
  89. <!-- 页面列表 -->
  90. <el-table :data="tableData" border resizable stripe style="width: 100%">
  91. <el-table-column prop="fileName" label="模板名称"> </el-table-column>
  92. <el-table-column prop="suffix" width="100" label="文件类型">
  93. </el-table-column>
  94. <el-table-column width="150" prop="typeName" label="模板类型">
  95. </el-table-column>
  96. <el-table-column width="180" prop="creationTime" label="上传时间">
  97. </el-table-column>
  98. <el-table-column width="150" prop="createUser" label="上传人">
  99. </el-table-column>
  100. <el-table-column label="状态" width="70">
  101. <template slot-scope="scope">
  102. <span v-if="scope.row.enable">
  103. <el-tooltip
  104. class="item"
  105. effect="dark"
  106. content="启用"
  107. placement="left"
  108. >
  109. <i class="el-icon-success" style="color: green"></i>
  110. </el-tooltip>
  111. </span>
  112. <span v-else>
  113. <el-tooltip
  114. class="item"
  115. effect="dark"
  116. content="禁用"
  117. placement="left"
  118. >
  119. <i class="el-icon-error" style="color: red"></i>
  120. </el-tooltip>
  121. </span>
  122. </template>
  123. </el-table-column>
  124. <el-table-column :context="_self" label="操作" width="280">
  125. <div slot-scope="scope">
  126. <el-button
  127. size="mini"
  128. type="primary"
  129. plain
  130. icon="el-icon-download"
  131. @click="downFile(scope.row)"
  132. >
  133. 下载
  134. </el-button>
  135. <el-button
  136. v-if="!scope.row.enable"
  137. size="mini"
  138. type="primary"
  139. plain
  140. @click="enable(scope.row)"
  141. >
  142. <i class="el-icon-check" aria-hidden="true"></i>启用
  143. </el-button>
  144. <el-button
  145. v-if="scope.row.enable"
  146. size="mini"
  147. type="danger"
  148. @click="disenable(scope.row)"
  149. >
  150. <i class="el-icon-close" aria-hidden="true"></i>禁用
  151. </el-button>
  152. <el-button
  153. size="mini"
  154. type="danger"
  155. plain
  156. icon="el-icon-remove-outline"
  157. @click="deleteFile(scope.row)"
  158. >
  159. 删除
  160. </el-button>
  161. </div>
  162. </el-table-column>
  163. </el-table>
  164. <div class="page pull-right">
  165. <el-pagination
  166. v-if="paginationShow"
  167. :current-page="currentPage"
  168. :page-size="pageSize"
  169. :page-sizes="[10, 20, 50, 100, 200, 300]"
  170. layout="total, sizes, prev, pager, next, jumper"
  171. :total="total"
  172. @current-change="handleCurrentChange"
  173. @size-change="handleSizeChange"
  174. />
  175. </div>
  176. </div>
  177. <el-dialog
  178. title="新增模板"
  179. width="550px"
  180. :visible.sync="fileModel"
  181. :close-on-click-modal="false"
  182. @close="closeFileModel"
  183. >
  184. <el-form
  185. ref="fileForm"
  186. :key="fileModelKey"
  187. :inline="true"
  188. :model="fileForm"
  189. :rules="fileRules"
  190. label-width="90px"
  191. >
  192. <el-row class="form-row">
  193. <el-form-item label="模板名称" prop="templateName">
  194. <el-input
  195. v-model="fileForm.templateName"
  196. class="pull-length"
  197. placeholder="请输入模板名称"
  198. ></el-input>
  199. </el-form-item>
  200. </el-row>
  201. <el-row class="form-row">
  202. <el-form-item label="模板类型" prop="type" class="form-item">
  203. <el-select v-model="fileForm.type" :clearable="true" class="input">
  204. <el-option label="试卷导出" value="PAPER_EXPORT"> </el-option>
  205. <el-option label="答案导出" value="ANWSER_EXPORT"> </el-option>
  206. <el-option label="离线试卷" value="OUTLINE_PAPER_EXPORT">
  207. </el-option>
  208. <el-option label="试卷预览" value="PAPER_VIEW"> </el-option>
  209. <el-option label="答案预览" value="ANWSER_VIEW"> </el-option>
  210. </el-select>
  211. </el-form-item>
  212. </el-row>
  213. <el-row class="form-row">
  214. <el-form-item label="文件" prop="dataFile">
  215. <el-input
  216. v-model="fileForm.fileName"
  217. class="pull-length"
  218. :readonly="true"
  219. placeholder="文件最大限制10M"
  220. />
  221. </el-form-item>
  222. <el-form-item>
  223. <el-upload
  224. :before-upload="handleUploadFile"
  225. accept=".ftl,.zip"
  226. action="/upload"
  227. >
  228. <el-button
  229. type="primary"
  230. size="small"
  231. icon="ios-cloud-upload-outline"
  232. >请选择文件
  233. </el-button>
  234. </el-upload>
  235. </el-form-item>
  236. </el-row>
  237. <el-row class="pull-center">
  238. <el-button type="primary" :loading="fileForm.loading" @click="subFile"
  239. >确定</el-button
  240. >
  241. <el-button @click="closeFileModel">取消</el-button>
  242. </el-row>
  243. </el-form>
  244. </el-dialog>
  245. <el-dialog
  246. title="配置信息"
  247. width="550px"
  248. :visible.sync="configModel"
  249. :close-on-click-modal="false"
  250. @close="closeConfigModel"
  251. >
  252. <el-form
  253. ref="configForm"
  254. :key="configModelKey"
  255. :inline="true"
  256. :model="configForm"
  257. :rules="configRules"
  258. label-width="90px"
  259. >
  260. <el-row v-if="isSuperAdmin" class="form-row">
  261. <el-form-item label="学校名称">
  262. <el-input
  263. v-model="configForm.orgName"
  264. disabled="true"
  265. class="pull-length"
  266. ></el-input>
  267. </el-form-item>
  268. </el-row>
  269. <el-row class="form-row">
  270. <el-form-item label="配置名称" prop="serviceName">
  271. <el-input
  272. v-model="configForm.serviceName"
  273. class="pull-length"
  274. placeholder="请输入serviceName"
  275. ></el-input>
  276. </el-form-item>
  277. </el-row>
  278. <el-row class="pull-center">
  279. <el-button
  280. type="primary"
  281. :loading="configForm.loading"
  282. @click="subConfig"
  283. >确定</el-button
  284. >
  285. <el-button @click="closeConfigModel">取消</el-button>
  286. </el-row>
  287. </el-form>
  288. </el-dialog>
  289. </section>
  290. </template>
  291. <script>
  292. import { CORE_API, QUESTION_API } from "@/constants/constants.js";
  293. import { mapState } from "vuex";
  294. export default {
  295. name: "ExportTemplate",
  296. data() {
  297. var reg = /\.zip|\.ftl$/;
  298. var validateFile = function (rule, value, callback) {
  299. if (value) {
  300. var upFileName = value.name;
  301. if (value.size > 1024 * 1024 * 10) {
  302. return callback(new Error("文件大小限制为10M"));
  303. } else if (!upFileName.match(reg)) {
  304. return callback(new Error("文件类型只能是ftl或zip"));
  305. } else {
  306. callback();
  307. }
  308. } else {
  309. callback();
  310. }
  311. };
  312. return {
  313. rootOrgList: [],
  314. loading: false,
  315. fileModel: false,
  316. fileModelKey: Math.random(),
  317. configModel: false,
  318. configModelKey: Math.random(),
  319. paginationShow: false,
  320. formSearch: {
  321. rootOrgId: null,
  322. fileName: "",
  323. type: "",
  324. },
  325. fileForm: {
  326. templateName: null,
  327. type: null,
  328. fileName: null,
  329. dataFile: null,
  330. loading: false,
  331. },
  332. configForm: {
  333. serviceName: null,
  334. orgName: null,
  335. loading: false,
  336. },
  337. tableData: [],
  338. currentPage: 1,
  339. pageSize: 10,
  340. total: 10,
  341. fileRules: {
  342. templateName: [
  343. {
  344. required: true,
  345. type: "string",
  346. message: "请输入模板名称",
  347. trigger: "change",
  348. },
  349. {
  350. pattern: /^[^\\/\\?%#&=\\+]*$/,
  351. message: "名称不能包含特殊字符 / ? % # & = +",
  352. trigger: "change",
  353. },
  354. ],
  355. type: [
  356. {
  357. required: true,
  358. type: "string",
  359. message: "请选择模板类型",
  360. trigger: "change",
  361. },
  362. ],
  363. dataFile: [
  364. {
  365. required: true,
  366. type: "object",
  367. message: "请选择文件",
  368. trigger: "change",
  369. },
  370. {
  371. validator: validateFile,
  372. type: "object",
  373. trigger: "change",
  374. },
  375. ],
  376. },
  377. configRules: {
  378. serviceName: [
  379. {
  380. required: true,
  381. type: "string",
  382. message: "请输入配置名称",
  383. trigger: "change",
  384. },
  385. {
  386. pattern: /^[^\\/\\?%#&=\\+]*$/,
  387. message: "名称不能包含特殊字符 / ? % # & = +",
  388. trigger: "change",
  389. },
  390. ],
  391. },
  392. };
  393. },
  394. computed: {
  395. ...mapState({ user: (state) => state.user }),
  396. isSuperAdmin() {
  397. return this.user.roleList.some((role) => role.roleCode == "SUPER_ADMIN");
  398. },
  399. },
  400. watch: {
  401. "formSearch.rootOrgId": {
  402. immediate: false,
  403. handler(val) {
  404. if (val == null) {
  405. this.curDir = "";
  406. } else {
  407. this.curDir = "/";
  408. this.formSearch.parentId = -1;
  409. this.handleSearchBtn();
  410. }
  411. },
  412. },
  413. },
  414. //初始化查询
  415. created() {
  416. this.init();
  417. },
  418. methods: {
  419. downFile(row) {
  420. window.location.href = row.fullFilePath;
  421. },
  422. enable(row) {
  423. var url =
  424. QUESTION_API +
  425. "/exportTemplate/enable/" +
  426. this.formSearch.rootOrgId +
  427. "/" +
  428. row.id;
  429. this.$httpWithMsg.put(url).then(() => {
  430. this.$notify({
  431. type: "success",
  432. message: "启用成功!",
  433. });
  434. this.searchForm();
  435. });
  436. },
  437. disenable(row) {
  438. var url =
  439. QUESTION_API +
  440. "/exportTemplate/disenable/" +
  441. this.formSearch.rootOrgId +
  442. "/" +
  443. row.id;
  444. this.$httpWithMsg.put(url).then(() => {
  445. this.$notify({
  446. type: "success",
  447. message: "禁用成功!",
  448. });
  449. this.searchForm();
  450. });
  451. },
  452. deleteFile(row) {
  453. this.$confirm("确定删除?", "提示", {
  454. confirmButtonText: "确定",
  455. cancelButtonText: "取消",
  456. type: "warning",
  457. }).then(() => {
  458. var url =
  459. QUESTION_API +
  460. "/exportTemplate/" +
  461. this.formSearch.rootOrgId +
  462. "/" +
  463. row.id;
  464. this.$httpWithMsg.delete(url).then(() => {
  465. this.$notify({
  466. type: "success",
  467. message: "删除成功!",
  468. });
  469. this.searchForm();
  470. });
  471. });
  472. },
  473. handleUploadFile(file) {
  474. this.fileForm.dataFile = file;
  475. this.fileForm.fileName = file.name;
  476. return false;
  477. },
  478. addFile() {
  479. if (this.formSearch.rootOrgId == null) {
  480. this.$notify({
  481. type: "warning",
  482. message: "请选择学校",
  483. });
  484. return;
  485. }
  486. this.fileModel = true;
  487. },
  488. operConfig() {
  489. if (this.formSearch.rootOrgId == null) {
  490. this.$notify({
  491. type: "warning",
  492. message: "请选择学校",
  493. });
  494. return;
  495. }
  496. this.loading = true;
  497. var url =
  498. QUESTION_API + "/exportTemplate/config/" + this.formSearch.rootOrgId;
  499. this.$httpWithMsg
  500. .get(url)
  501. .then((response) => {
  502. this.configForm.serviceName = response.data.exportServiceName;
  503. if (this.isSuperAdmin) {
  504. for (const org of this.rootOrgList) {
  505. if (this.formSearch.rootOrgId == org.id) {
  506. this.configForm.orgName = org.name;
  507. break;
  508. }
  509. }
  510. }
  511. this.configModel = true;
  512. })
  513. .finally(() => (this.loading = false));
  514. },
  515. async subFile() {
  516. const res = await this.$refs.fileForm.validate();
  517. if (res === false) {
  518. return;
  519. }
  520. this.fileForm.loading = true;
  521. var params =
  522. "?templateName=" +
  523. this.fileForm.templateName +
  524. "&type=" +
  525. this.fileForm.type;
  526. var url =
  527. QUESTION_API +
  528. "/exportTemplate/add/" +
  529. this.formSearch.rootOrgId +
  530. params;
  531. let formData = new FormData();
  532. formData.append("dataFile", this.fileForm.dataFile);
  533. this.$httpWithMsg
  534. .post(url, formData)
  535. .then(() => {
  536. this.$notify({
  537. type: "success",
  538. message: "上传成功!",
  539. });
  540. this.closeFileModel();
  541. this.searchForm();
  542. })
  543. .finally(() => (this.fileForm.loading = false));
  544. },
  545. async subConfig() {
  546. const res = await this.$refs.configForm.validate();
  547. if (res === false) {
  548. return;
  549. }
  550. this.configForm.loading = true;
  551. var params = "?serviceName=" + this.configForm.serviceName;
  552. var url =
  553. QUESTION_API +
  554. "/exportTemplate/config/" +
  555. this.formSearch.rootOrgId +
  556. params;
  557. this.$httpWithMsg
  558. .put(url)
  559. .then(() => {
  560. this.$notify({
  561. type: "success",
  562. message: "配置成功!",
  563. });
  564. this.closeConfigModel();
  565. })
  566. .finally(() => (this.configForm.loading = false));
  567. },
  568. closeFileModel() {
  569. this.fileModel = false;
  570. this.$refs.fileForm.resetFields();
  571. this.fileModelKey = Math.random();
  572. this.fileForm.fileName = null;
  573. this.fileForm.type = null;
  574. this.fileForm.dataFile = null;
  575. this.fileForm.templateName = null;
  576. },
  577. closeConfigModel() {
  578. this.configModel = false;
  579. this.$refs.configForm.resetFields();
  580. this.configModelKey = Math.random();
  581. this.configForm.orgName = null;
  582. this.configForm.serviceName = null;
  583. },
  584. handleSearchBtn() {
  585. this.currentPage = 1;
  586. this.searchForm();
  587. },
  588. handleSizeChange(val) {
  589. this.pageSize = val;
  590. this.currentPage = 1;
  591. this.searchForm();
  592. },
  593. handleCurrentChange(val) {
  594. this.currentPage = val;
  595. this.searchForm();
  596. },
  597. //查询
  598. searchForm() {
  599. if (this.formSearch.rootOrgId == null) {
  600. this.$notify({
  601. type: "warning",
  602. message: "请选择学校",
  603. });
  604. return;
  605. }
  606. this.loading = true;
  607. var url =
  608. QUESTION_API +
  609. "/exportTemplate/page/" +
  610. this.currentPage +
  611. "/" +
  612. this.pageSize;
  613. this.$httpWithMsg
  614. .get(url, { params: this.formSearch })
  615. .then((response) => {
  616. this.tableData = response.data.content;
  617. this.total = response.data.totalElements;
  618. this.loading = false;
  619. this.$nextTick(function () {
  620. this.paginationShow = true;
  621. });
  622. })
  623. .finally(() => (this.loading = false));
  624. },
  625. init() {
  626. if (this.isSuperAdmin) {
  627. this.$httpWithMsg
  628. .get(CORE_API + "/org/getRootOrgList")
  629. .then((response) => {
  630. this.rootOrgList = response.data;
  631. });
  632. } else {
  633. this.formSearch.rootOrgId = this.user.rootOrgId;
  634. this.searchForm();
  635. }
  636. },
  637. },
  638. };
  639. </script>
  640. <style scoped src="../styles/Common.css"></style>
  641. <style scoped>
  642. .page {
  643. margin-top: 10px;
  644. }
  645. .pull-length {
  646. width: 300px;
  647. }
  648. .details-length {
  649. width: 400px;
  650. }
  651. .pull-center {
  652. margin-top: 20px;
  653. }
  654. .editForm .el-form-item {
  655. margin-bottom: 12px;
  656. }
  657. .form-row {
  658. margin-top: 20px;
  659. }
  660. </style>