index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div>
  3. <a class="button is-link" @click="startCreation()"
  4. >新建{{ createTitle }}作业</a
  5. >
  6. <!--新建文档作业模态框-->
  7. <b-modal :active.sync="isCreateModalActive" :width="640" scroll="keep">
  8. <div class="card">
  9. <div class="title">新建{{ createTitle }}作业</div>
  10. <div class="content">
  11. <b-field label="题目名称">
  12. <b-input v-model="problemName"></b-input>
  13. </b-field>
  14. <b-field
  15. label="作业名称"
  16. :type="$v.params.name.$error ? 'is-danger' : ''"
  17. :message="$v.params.name.$error ? '请填写作业名称' : ''"
  18. >
  19. <b-input
  20. placeholder="请填写作业名称"
  21. v-model="$v.params.name.$model"
  22. ></b-input>
  23. </b-field>
  24. <b-field
  25. label="作业描述"
  26. :type="$v.params.description.$error ? 'is-danger' : ''"
  27. :message="$v.params.description.$error ? '请填写作业描述' : ''"
  28. >
  29. <b-input
  30. type="textarea"
  31. placeholder="请填写作业描述"
  32. v-model="$v.params.description.$model"
  33. ></b-input>
  34. </b-field>
  35. <b-field
  36. label="开始时间"
  37. :type="$v.params.startAt.$error ? 'is-danger' : ''"
  38. :message="$v.params.startAt.$error ? '请填写作业开始时间' : ''"
  39. >
  40. <flat-pickr
  41. placeholder="Click to select..."
  42. class="input"
  43. v-model="$v.params.startAt.$model"
  44. :config="startAtConfig"
  45. ></flat-pickr>
  46. </b-field>
  47. <b-field
  48. label="结束时间"
  49. :type="$v.params.endAt.$error ? 'is-danger' : ''"
  50. :message="$v.params.endAt.$error ? '请填写作业结束时间' : ''"
  51. >
  52. <flat-pickr
  53. placeholder="Click to select..."
  54. class="input"
  55. v-model="$v.params.endAt.$model"
  56. :config="endAtConfig"
  57. ></flat-pickr>
  58. </b-field>
  59. <a
  60. class="button is-link"
  61. :class="{ 'is-loading': loadingCreateAssignment }"
  62. @click="createAssignment()"
  63. >
  64. 确认新建
  65. </a>
  66. </div>
  67. </div>
  68. </b-modal>
  69. <!--搜索题目模态框-->
  70. <b-modal :active.sync="isSearchModalActive">
  71. <div class="card">
  72. <div class="title">请先查找题目</div>
  73. <div class="content">
  74. <b-field
  75. :type="$v.searchContent.$error ? 'is-danger' : ''"
  76. :message="$v.params.endAt.$error ? '' : ''"
  77. >
  78. <b-input
  79. placeholder="输入关键字模糊查找"
  80. type="search"
  81. v-model="$v.searchContent.$model"
  82. @keyup.enter.native="search(searchContent)"
  83. expanded
  84. >
  85. </b-input>
  86. <p class="control">
  87. <button
  88. class="button is-link"
  89. :class="{ 'is-loading': loadingSearchQuestions }"
  90. @click="search(searchContent)"
  91. >
  92. 查找
  93. </button>
  94. </p>
  95. </b-field>
  96. </div>
  97. </div>
  98. </b-modal>
  99. <!--题目列表展示框-->
  100. <b-modal :active.sync="isProblemListModalActive">
  101. <b-notification type="is-danger" :active.sync="isServerError">
  102. {{ errorMassage }}
  103. </b-notification>
  104. <div>
  105. <div class="card" v-if="isAnyQuestion">
  106. <div class="title">选择题目</div>
  107. <div class="content">
  108. <div class="question-list">
  109. <b-table :data="questions" detailed detail-key="id">
  110. <template slot-scope="props">
  111. <b-table-column
  112. field="id"
  113. label="ID"
  114. width="40"
  115. numeric
  116. sortable
  117. >
  118. {{ props.row.id }}
  119. </b-table-column>
  120. <b-table-column label="题目名称">
  121. <a @click="selectAndCreate(props.row)">{{
  122. props.row.name
  123. }}</a>
  124. </b-table-column>
  125. <b-table-column label="题目描述" width="100">
  126. <div class="description">{{ props.row.description }}</div>
  127. </b-table-column>
  128. <b-table-column
  129. field="difficulty"
  130. label="题目难度"
  131. sortable
  132. centered
  133. >
  134. <span
  135. :class="[
  136. 'tag',
  137. `${getDifficultyClass(props.row.difficulty)}`
  138. ]"
  139. >
  140. {{ getDifficultyType(props.row.difficulty) }}
  141. </span>
  142. </b-table-column>
  143. <b-table-column
  144. label="平均时长"
  145. field="expectTime"
  146. sortable
  147. centered
  148. >
  149. {{ props.row.expectTime }}分钟
  150. </b-table-column>
  151. </template>
  152. <template slot="detail" slot-scope="props">
  153. <div>{{ props.row.description }}</div>
  154. </template>
  155. </b-table>
  156. </div>
  157. </div>
  158. </div>
  159. <div class="card" v-else>
  160. 没有查找到题目,请<a @click="reResearch()">重新查找</a>
  161. </div>
  162. </div>
  163. </b-modal>
  164. </div>
  165. </template>
  166. <script>
  167. import { getTeacherKeywordQuestionsByCode } from "@/api/question";
  168. import { getTeacherKeywordQuestionsByDoc } from "@/api/question";
  169. import { postDocAssignment } from "@/api/assignment";
  170. import { postCodeAssignment } from "@/api/assignment";
  171. import timeMixins from "@/mixins/time";
  172. import { required } from "vuelidate/lib/validators";
  173. import pathMixins from "@/mixins/path";
  174. import { difficultyType } from "@/data/questionDifficulty";
  175. import { difficultyClass } from "@/data/questionDifficulty";
  176. export default {
  177. props: {
  178. courseId: {
  179. type: Number
  180. },
  181. assignType: {
  182. type: Number
  183. }
  184. },
  185. mounted() {
  186. if (this.assignType === 1) {
  187. this.createTitle = "文档";
  188. this.postParam = "DOCUMENT";
  189. } else {
  190. this.createTitle = "代码";
  191. this.postParam = "CODE";
  192. }
  193. },
  194. data() {
  195. return {
  196. params: {
  197. name: null,
  198. description: null,
  199. startAt: null,
  200. endAt: null,
  201. problem: null //题目编号
  202. },
  203. createTitle: "",
  204. postParam: "",
  205. myPromise: null,
  206. problemName: "",
  207. searchContent: "",
  208. questions: [],
  209. isAnyQuestion: false,
  210. // 控制modal活动
  211. isCreateModalActive: false,
  212. isSearchModalActive: false,
  213. isProblemListModalActive: false,
  214. startAtConfig: {
  215. ...this.getDefaultConfig(),
  216. minDate: "today",
  217. maxDate: null
  218. },
  219. endAtConfig: {
  220. ...this.getDefaultConfig(),
  221. minDate: "today",
  222. maxDate: null
  223. },
  224. errorMassage: null,
  225. isServerError: false,
  226. submitting: false,
  227. // 转圈圈
  228. loadingSearchQuestions: false,
  229. loadingCreateAssignment: false
  230. };
  231. },
  232. methods: {
  233. /**
  234. * 准备新建
  235. */
  236. startCreation() {
  237. if (this.submitting) return;
  238. this.isSearchModalActive = true;
  239. },
  240. /**
  241. * 搜索题目
  242. */
  243. search(content) {
  244. if (this.submitting) return;
  245. this.isServerError = false;
  246. this.$v.searchContent.$touch();
  247. if (!this.$v.searchContent.$invalid) {
  248. this.loadingSearchQuestions = true;
  249. this.submitting = true;
  250. try {
  251. let questionPromise = null;
  252. if (this.assignType === 1) {
  253. questionPromise = getTeacherKeywordQuestionsByDoc(content);
  254. } else {
  255. questionPromise = getTeacherKeywordQuestionsByCode(content);
  256. }
  257. questionPromise.then(res => {
  258. this.questions = res.data;
  259. this.isSearchModalActive = false;
  260. this.loadingSearchQuestions = false;
  261. this.isProblemListModalActive = true;
  262. if (this.questions.length !== 0) {
  263. this.isAnyQuestion = true;
  264. }
  265. });
  266. } catch (e) {
  267. this.errorMassage = e.message;
  268. this.isServerError = true;
  269. } finally {
  270. this.submitting = false;
  271. }
  272. }
  273. },
  274. selectAndCreate(problem) {
  275. this.params.problem = problem.id;
  276. this.problemName = problem.name;
  277. this.isProblemListModalActive = false;
  278. this.isCreateModalActive = true;
  279. },
  280. /**
  281. * 重新查找
  282. */
  283. reResearch() {
  284. this.isProblemListModalActive = false;
  285. this.isSearchModalActive = true;
  286. },
  287. /**
  288. * 确认新建
  289. */
  290. createAssignment() {
  291. if (this.submitting) return;
  292. this.$v.params.$touch();
  293. if (!this.$v.params.$invalid) {
  294. this.loadingCreateAssignment = true;
  295. this.submitting = true;
  296. this.params["type"] = this.postParam;
  297. // this.parseParams();
  298. const param = {
  299. ...this.params,
  300. startAt: parseInt(this.params.startAt),
  301. endAt: parseInt(this.params.endAt)
  302. };
  303. if (this.assignType === 1) {
  304. // 文档作业
  305. this.myPromise = postDocAssignment(param, this.courseId);
  306. } else {
  307. // 代码作业
  308. this.myPromise = postCodeAssignment(param, this.courseId);
  309. }
  310. this.myPromise
  311. .then(res => {
  312. //创建成功
  313. this.isCreateModalActive = false;
  314. this.submitting = false;
  315. if (res.code === 0) {
  316. if (this.assignType === 1) {
  317. this.$router.push({
  318. path: `${this.prefix}/review?documentHwId=${res.data.id}`
  319. });
  320. }
  321. this.$emit("sendCreatedAssignment", res.data);
  322. this.loadingCreateAssignment = false;
  323. } else {
  324. //创建失败
  325. this.isCreateModalActive = false;
  326. this.loadingCreateAssignment = false;
  327. this.$dialog.alert({
  328. title: "创建失败",
  329. message: res.message,
  330. type: "is-danger",
  331. hasIcon: true
  332. });
  333. }
  334. })
  335. .catch(e => {
  336. this.submitting = false;
  337. this.$toast.open({
  338. message: e.message || "服务器未知错误",
  339. type: "is-danger"
  340. });
  341. });
  342. }
  343. },
  344. getDifficultyType(level) {
  345. return difficultyType(level);
  346. },
  347. getDifficultyClass(level) {
  348. return difficultyClass(level);
  349. }
  350. },
  351. mixins: [timeMixins, pathMixins],
  352. validations: {
  353. params: {
  354. name: {
  355. required
  356. },
  357. description: {
  358. required
  359. },
  360. startAt: {
  361. required
  362. },
  363. endAt: {
  364. required
  365. }
  366. },
  367. searchContent: {
  368. required
  369. }
  370. },
  371. watch: {
  372. isCreateModalActive(newValue) {
  373. if (newValue === false) {
  374. this.$v.params.$reset();
  375. }
  376. },
  377. isSearchModalActive(newValue) {
  378. if (newValue === false) {
  379. this.$v.searchContent.$reset();
  380. }
  381. }
  382. }
  383. };
  384. </script>
  385. <style lang="scss" scoped>
  386. .card {
  387. text-align: left;
  388. padding: 30px;
  389. .title {
  390. font-size: 1.25rem;
  391. small {
  392. color: gray;
  393. font-size: 1rem;
  394. }
  395. }
  396. .content {
  397. a {
  398. margin-top: 30px;
  399. width: 100%;
  400. }
  401. }
  402. }
  403. .description {
  404. overflow: hidden;
  405. text-overflow: ellipsis;
  406. -webkit-box-orient: vertical;
  407. -webkit-line-clamp: 1;
  408. word-wrap: break-word;
  409. word-break: break-all;
  410. display: -webkit-box;
  411. }
  412. </style>