ImportPaperInfo.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <section class="content">
  3. <LinkTitlesCustom :currentPaths="['word文件上传']" />
  4. <!-- 正文信息 -->
  5. <div
  6. class="box-body"
  7. v-loading.body="fileLoading"
  8. element-loading-text="试题上传中,请稍后..."
  9. >
  10. <el-form
  11. :inline="true"
  12. :model="formSearch"
  13. label-position="right"
  14. label-width="100px"
  15. >
  16. <el-row>
  17. <el-form-item label="课程名称" label-width="120px" class="pull-left">
  18. <el-select
  19. v-model="formSearch.courseNo"
  20. class="form_width"
  21. filterable
  22. :remote-method="getCourses"
  23. remote
  24. clearable
  25. placeholder="请选择"
  26. @change="searchCourseName"
  27. >
  28. <el-option
  29. v-for="item in courseInfoSelect"
  30. :label="item.courseInfo"
  31. :value="item.courseNo"
  32. :key="item.courseNo"
  33. >
  34. </el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item class="pull-right">
  38. <el-button type="primary" @click="back"
  39. ><i class="el-icon-arrow-left"></i> 返回</el-button
  40. >
  41. </el-form-item>
  42. </el-row>
  43. <el-row>
  44. <el-form-item label="试卷名称" label-width="120px" class="pull-left">
  45. <el-input
  46. placeholder="试卷名称"
  47. class="form_width"
  48. v-model="formSearch.name"
  49. ></el-input>
  50. </el-form-item>
  51. </el-row>
  52. <el-row>
  53. <el-form-item label="总分校验" label-width="120px" class="pull-left">
  54. <el-radio v-model="scoreCheck" label="1">开启</el-radio>
  55. <el-radio v-model="scoreCheck" label="0">关闭</el-radio>
  56. </el-form-item>
  57. </el-row>
  58. <el-row v-if="scoreCheck == 1">
  59. <el-form-item label="试卷总分" label-width="120px" class="pull-left">
  60. <el-input
  61. placeholder="试卷总分"
  62. class="form_width"
  63. v-model="formSearch.totalScore"
  64. ></el-input>
  65. </el-form-item>
  66. </el-row>
  67. <!--
  68. <el-row>
  69. <el-form-item label="相同大题名称" label-width="120px" class="pull-left">
  70. <el-radio v-model="formSearch.sameName" label="1">合并</el-radio>
  71. <el-radio v-model="formSearch.sameName" label="0">不合并</el-radio>
  72. </el-form-item>
  73. </el-row>
  74. -->
  75. <el-row>
  76. <el-form-item>
  77. <el-upload
  78. class="form_left"
  79. ref="upload"
  80. accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  81. :action="uploadAction"
  82. :headers="uploadHeaders"
  83. :data="uploadData"
  84. :before-upload="beforeUpload"
  85. :on-progress="uploadProgress"
  86. :on-success="uploadSuccess"
  87. :on-error="uploadError"
  88. :file-list="fileList"
  89. :auto-upload="false"
  90. :multiple="false"
  91. >
  92. <el-button slot="trigger" type="primary">选择文件</el-button>
  93. <el-button
  94. style="margin-left:10px;"
  95. type="primary"
  96. @click="submitUpload"
  97. >确认上传
  98. </el-button>
  99. <el-button
  100. style="margin-left: 10px;"
  101. type="danger"
  102. @click="removeFile"
  103. >清空文件
  104. </el-button>
  105. <div slot="tip" class="el-upload__tip">只能上传docx文件</div>
  106. </el-upload>
  107. </el-form-item>
  108. </el-row>
  109. </el-form>
  110. <el-dialog title="错误提示" v-model="errDialog">
  111. <span style="font-size: large">{{ errMessage }} !</span>
  112. <span slot="footer" class="dialog-footer">
  113. <el-button @click="errDialog = false">确定</el-button>
  114. </span>
  115. </el-dialog>
  116. </div>
  117. </section>
  118. </template>
  119. <script>
  120. import { CORE_API, QUESTION_API } from "@/constants/constants";
  121. import { mapState } from "vuex";
  122. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  123. export default {
  124. components: { LinkTitlesCustom },
  125. data() {
  126. return {
  127. scoreCheck: "0",
  128. formSearch: {
  129. courseNo: "",
  130. couresName: "",
  131. name: "",
  132. totalScore: "",
  133. courseLevel: "",
  134. sameName: "0"
  135. },
  136. courseList: [],
  137. uploadAction: "",
  138. errMessage: "",
  139. uploadData: {},
  140. fileLoading: false,
  141. button_tpye: false,
  142. errDialog: false,
  143. fileList: [],
  144. uploadHeaders: {}
  145. };
  146. },
  147. methods: {
  148. searchCourseName() {
  149. for (let course of this.courseList) {
  150. if (course.code == this.formSearch.courseNo) {
  151. this.formSearch.courseName = course.name;
  152. this.formSearch.courseLevel = course.level;
  153. console.log(this.formSearch.courseLevel);
  154. }
  155. }
  156. },
  157. beforeUpload(file) {
  158. console.log(file);
  159. },
  160. uploadProgress() {
  161. console.log("uploadProgress");
  162. },
  163. uploadSuccess(response) {
  164. this.$notify({
  165. message: "上传成功",
  166. type: "success"
  167. });
  168. this.fileLoading = false;
  169. this.$router.push({
  170. path: "/edit_paper/" + response.id + "/import_paper"
  171. });
  172. },
  173. uploadError(err) {
  174. console.log(err);
  175. var result = err.message.match(/\{.+}/);
  176. var errMessage = JSON.parse(result[0]).desc;
  177. this.errDialog = true;
  178. this.errMessage = errMessage;
  179. this.fileLoading = false;
  180. },
  181. initUpload() {
  182. this.fileList = [];
  183. this.formSearch.name = "";
  184. this.formSearch.courseNo = "";
  185. },
  186. checkUpload() {
  187. if (!this.formSearch.courseNo) {
  188. this.$notify({
  189. message: "课程名称不能为空",
  190. type: "error"
  191. });
  192. return false;
  193. } else {
  194. this.uploadData.courseNo = this.formSearch.courseNo;
  195. this.uploadData.courseName = this.formSearch.courseName;
  196. this.uploadData.level = this.formSearch.courseLevel;
  197. this.uploadData.sameName = this.formSearch.sameName;
  198. }
  199. if (!this.formSearch.name) {
  200. this.$notify({
  201. message: "试卷名称不能为空",
  202. type: "error"
  203. });
  204. return false;
  205. } else {
  206. this.uploadData.name = this.formSearch.name;
  207. }
  208. if (this.scoreCheck == 1 && !this.formSearch.totalScore) {
  209. this.$notify({
  210. message: "试卷总分不能为空",
  211. type: "error"
  212. });
  213. return false;
  214. } else {
  215. this.uploadData.totalScore = this.formSearch.totalScore;
  216. }
  217. var fileList = this.$refs.upload.uploadFiles;
  218. if (fileList.length == 0) {
  219. this.$notify({
  220. message: "上传文件不能为空",
  221. type: "error"
  222. });
  223. return false;
  224. }
  225. if (fileList.length > 1) {
  226. this.$notify({
  227. message: "每次只能上传一个word文件",
  228. type: "error"
  229. });
  230. return false;
  231. }
  232. for (let file of fileList) {
  233. if (!file.name.endsWith(".docx")) {
  234. this.$notify({
  235. message: "上传文件必须为docx格式",
  236. type: "error"
  237. });
  238. this.initUpload();
  239. return false;
  240. }
  241. }
  242. return true;
  243. },
  244. //确定上传
  245. submitUpload() {
  246. console.log("this form:", this.formSearch);
  247. if (!this.checkUpload()) {
  248. return false;
  249. }
  250. this.$refs.upload.submit();
  251. this.fileLoading = true;
  252. },
  253. //清空文件
  254. removeFile() {
  255. // this.fileList = [];
  256. this.$refs.upload.clearFiles();
  257. },
  258. //返回
  259. back() {
  260. this.$router.push({ path: "/questions/import_paper/0" });
  261. },
  262. //查询所有课程
  263. getCourses(query) {
  264. query = query.trim();
  265. if (query) {
  266. if (!(query.indexOf("(") > -1 && query.indexOf(")") > -1)) {
  267. this.courseLoading = true;
  268. this.$http
  269. .get(CORE_API + "/course/query?name=" + query + "&enable=true")
  270. .then(response => {
  271. this.courseList = response.data;
  272. this.courseLoading = false;
  273. });
  274. }
  275. } else {
  276. this.courseList = [];
  277. }
  278. }
  279. },
  280. computed: {
  281. ...mapState({ user: state => state.user }),
  282. courseInfoSelect() {
  283. var courseList = [];
  284. for (let course of this.courseList) {
  285. var courseInfo = course.name + "(" + course.code + ")";
  286. var courseNo = course.code;
  287. courseList.push({ courseNo: courseNo, courseInfo: courseInfo });
  288. }
  289. return courseList;
  290. }
  291. },
  292. watch: {
  293. scoreCheck: function() {
  294. if (this.scoreCheck == 0) {
  295. this.formSearch.totalScore = "";
  296. }
  297. }
  298. },
  299. created() {
  300. this.uploadAction = QUESTION_API + "/importPaper";
  301. this.uploadData = { name: this.formSearch.name };
  302. this.uploadHeaders = {
  303. key: this.user.key,
  304. token: this.user.token
  305. };
  306. }
  307. };
  308. </script>
  309. <style scoped>
  310. .form_width {
  311. width: 200px;
  312. }
  313. .form_left {
  314. margin-left: 50px;
  315. }
  316. </style>