TaskEditor.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <script setup lang="ts">
  2. import { ref, onMounted, watch } from "vue";
  3. import { getClassInfos, getCourseList, getCurriculumList, getKnowledgeList, getDefectsList, getTaskDetail, saveTaskInfo } from "../../api/techer/taskEditor";
  4. import { useRoute } from "vue-router"
  5. import router from '../../router/index'
  6. import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
  7. import { Back } from "@element-plus/icons-vue";
  8. const currStep = ref(0);
  9. const classInfos = ref([]);
  10. const curriculumList = ref([]);
  11. const courseInfos = ref(0);
  12. const loadingTable = ref(false);
  13. const knowledgeList = ref([]);
  14. const normalDefectsList = ref([]);
  15. const otherDefectsList = ref([]);
  16. const deffectsCheckeds: any = ref({});
  17. const durationStudyMins: any = ref({});
  18. const taskId:any = ref(null);
  19. const linkId:any=ref(null);
  20. const form = ref({
  21. id: "",
  22. name:"",
  23. classId: null,
  24. curriculumId:null,
  25. courseId: "",
  26. mustPipDefectIds:[],
  27. optionChapters:[],
  28. });
  29. const getCourseChecked = () => {
  30. let ary:any = courseInfos.value;
  31. //let rslt: any = [];
  32. for (let i = 0, len = ary.length; i < len; i++) {
  33. if (ary[i].checked) {
  34. //rslt.push(ary[i].id);
  35. return ary[i].id;
  36. }
  37. }
  38. return "";
  39. }
  40. const getOptionChapters = () => {
  41. let rslt: any = [];
  42. for (let k in durationStudyMins.value) {
  43. let val = durationStudyMins.value[k];
  44. rslt.push({
  45. chapterId: k,
  46. durationStudyMin:val
  47. });
  48. }
  49. return rslt;
  50. }
  51. const getMustPipDefectIds = () => {
  52. let rslt: any = [];
  53. for (let k in deffectsCheckeds.value) {
  54. if (deffectsCheckeds.value[k]) {
  55. rslt.push(k);
  56. }
  57. }
  58. return rslt;
  59. }
  60. const saveTask = () => {
  61. form.value.courseId = getCourseChecked();
  62. form.value.optionChapters = getOptionChapters();
  63. form.value.mustPipDefectIds = getMustPipDefectIds();
  64. if (form.value.classId == null) {
  65. ElMessage({
  66. showClose: true,
  67. message: '尚未选择班级',
  68. type: 'warning',
  69. })
  70. return;
  71. }
  72. if (form.value.courseId == null ||(form.value.courseId.toString()).length<1) {
  73. ElMessage({
  74. showClose: true,
  75. message: '尚未选择需要发布的课程',
  76. type: 'warning',
  77. })
  78. return;
  79. }
  80. form.value.id = taskId.value;
  81. saveTaskInfo(form.value).then((e: any) => {
  82. if (e.data.code == 0) {
  83. ElMessage({
  84. showClose: true,
  85. message: "保存成功",
  86. type: 'success',
  87. });
  88. } else {
  89. ElMessage({
  90. showClose: true,
  91. message: '保存失败:' + e.msg || "系统发生异常",
  92. type: 'warning',
  93. });
  94. }
  95. });
  96. }
  97. const preStep = () => {
  98. currStep.value--;
  99. }
  100. const nextStep = () => {
  101. if (currStep.value == 0) {
  102. if (form.value.classId == null || form.value.classId.toString().length<1) {
  103. ElMessage({
  104. showClose: true,
  105. message: '尚未选择班级',
  106. type: 'warning',
  107. })
  108. return;
  109. }
  110. // form.course = getCourseChecked();
  111. if (form.value.courseId==null||form.value.courseId.toString().length < 1) {
  112. ElMessage({
  113. showClose: true,
  114. message: '尚未选择需要发布的课程',
  115. type: 'warning',
  116. })
  117. return;
  118. }
  119. }
  120. currStep.value++;
  121. }
  122. /**设置选中的课程 */
  123. const changeCheckCourse = (id:any,e:any) => {
  124. let ary2:any = courseInfos.value;
  125. form.value.courseId = "";
  126. for (let i = 0, len = ary2.length; i < len; i++) {
  127. let item = ary2[i];
  128. let id2 = item.id;
  129. if (id2 == id) {
  130. item.checked = e.target.checked;
  131. form.value.courseId = id;
  132. } else {
  133. item.checked = false;
  134. }
  135. }
  136. ///设置选中后根据课程的id获取知识点
  137. }
  138. /**初始化设置选中项 */
  139. const setCourseChecked = (id:any) => {
  140. let ary2:any = courseInfos.value;
  141. for (let i = 0, len = ary2.length; i < len; i++) {
  142. let id2 = ary2[i].id;
  143. if (id2 == id) {
  144. ary2[i].checked = true;
  145. } else {
  146. ary2[i].checked = false;
  147. }
  148. }
  149. }
  150. /** */
  151. const getImage = (url:any) => {
  152. if (url == null)
  153. return null;
  154. if (url.indexOf("http") == 0) {
  155. return `url(${url})`;
  156. }
  157. let obj = new URL(`../../${url}`, import.meta.url).href;
  158. let rslt = `url(${obj})`;
  159. return rslt;
  160. }
  161. /**点击设置缺陷的选择 */
  162. const changeCheckDeffects = (id: any, e: any, type: any) => {
  163. deffectsCheckeds.value[id] = e.target.checked;
  164. }
  165. /**获取编辑的数据 */
  166. const getEditorForm = () => {
  167. if (taskId.value != null && taskId.value.toString().length > 0) {
  168. getTaskDetail(taskId.value).then((e: any) => {
  169. if (e.data.code == 0) {
  170. form.value = e.data.data;
  171. setCourseChecked(form.value.courseId);
  172. if (form.value.mustPipDefectIds != null) {
  173. for (let i = 0, len = form.value.mustPipDefectIds.length; i < len; i++) {
  174. let item = form.value.mustPipDefectIds[i];
  175. deffectsCheckeds.value[item] = true;
  176. }
  177. }
  178. console.log(form.value);
  179. if (form.value.optionChapters != null) {
  180. for (let i = 0, len = form.value.optionChapters.length; i < len; i++) {
  181. let item = form.value.optionChapters[i];
  182. durationStudyMins.value[item.chapterId]=item.durationStudyMin;
  183. }
  184. }
  185. }
  186. });
  187. }
  188. }
  189. const back2Task = () => {
  190. if(linkId.value!=null){
  191. router.push({
  192. path: "/TaskMng/"+linkId.value,
  193. });
  194. }else{
  195. router.push({
  196. path: "/TaskMng",
  197. });
  198. }
  199. }
  200. const setDurationStudyMinInfo = (data:any) => {
  201. for (let i = 0, len = data.length; i < len; i++) {
  202. let item = data[i];
  203. let id = item.id;
  204. durationStudyMins.value[id] = durationStudyMins.value[id] || item.durationStudyMin;
  205. if (item.children != null) {
  206. setDurationStudyMinInfo(item.children);
  207. }
  208. }
  209. }
  210. watch(() => form.value.courseId, (n, o) => {
  211. //// 根据选中的课程获取章节的列表
  212. getKnowledgeList(n).then((e: any) => {
  213. if (e.data.code == 0) {
  214. //for (let i = 0, len = e.data.data==null?0: e.data.data.length; i < len; i++) {
  215. // let id = e.data.data[i].id;
  216. // durationStudyMins.value[id] = durationStudyMins.value[id] || e.data.data[i].durationStudyMin;
  217. //}
  218. setDurationStudyMinInfo(e.data.data);
  219. console.log(durationStudyMins.value);
  220. knowledgeList.value = e.data.data;
  221. }
  222. });
  223. /////根据选中的课程获取缺陷的列表
  224. getDefectsList(n).then((e: any) => {
  225. let aryN:any = [];
  226. let aryO:any = [];
  227. let list = e.data.data.list;
  228. for (let i = 0, len = list.length; i < len; i++) {
  229. let item = list[i];
  230. if (item.type == 1) {
  231. aryN.push(item);
  232. } else {
  233. aryO.push(item);
  234. }
  235. deffectsCheckeds.value[item.id] = deffectsCheckeds.value[item.id]|| false;
  236. }
  237. normalDefectsList.value = aryN;
  238. otherDefectsList.value = aryO;
  239. });
  240. });
  241. watch(() => form.value.classId, (n, o) => {
  242. getCurriculumList(n).then((e: any) => {
  243. // form.value.curriculumId = null;
  244. let list = e.data.data.list;
  245. curriculumList.value = list;
  246. if (form.value.curriculumId != null) {
  247. if (!list.find((e: any) => {
  248. return e.id == form.value.curriculumId;
  249. })) {
  250. form.value.curriculumId = null;
  251. }
  252. }
  253. });
  254. });
  255. onMounted(() => {
  256. const route = useRoute();
  257. console.log(route);
  258. if (route.params.taskId != null&&route.params.taskId.toString().length>0) {
  259. taskId.value = route.params.taskId;
  260. }
  261. if(route.query.linkId!=null){
  262. linkId.value=route.query.linkId;
  263. }
  264. getClassInfos().then((e: any) => {
  265. classInfos.value = e.data.data.list;
  266. });
  267. ////课程列表先获取后再与内容绑定
  268. getCourseList().then((e: any) => {
  269. if (e.data.code == 0) {
  270. let list = e.data.data.list;
  271. courseInfos.value = list;
  272. getEditorForm();
  273. setCourseChecked(form.value.courseId);
  274. }
  275. });
  276. });
  277. </script>
  278. <template>
  279. <div class="task-editor-wrapper">
  280. <div class="task-editor-steps-wrapper">
  281. <div class="task-back" @click="back2Task">
  282. <!--<el-icon style="margin-right:1rem; border-radius:10px; border:1px solid #000;"><Back /></el-icon>-->
  283. <el-button circle :icon="Back"></el-button>
  284. <div style="margin-left:0.5rem;">返回任务</div>
  285. </div>
  286. <el-steps direction="vertical" :active="currStep" finish-status="success">
  287. <el-step title="基础设置" />
  288. <el-step title="知识点编辑" />
  289. <el-step title="管道缺陷" />
  290. </el-steps>
  291. <div class="task-step-opts">
  292. <el-button v-if="currStep>0" type="default" @click="preStep()">上一步</el-button>
  293. <el-button v-if="currStep<2" type="default" @click="nextStep()">下一步</el-button>
  294. <el-button v-if="currStep==2" type="primary" @click="saveTask()">保存</el-button>
  295. </div>
  296. </div>
  297. <div class="task-editor-panel">
  298. <div v-show="currStep==0" class="base-setting setting-info">
  299. <h3>任务名称</h3>
  300. <el-input v-model="form.name" style="width:300px;" />
  301. <h3>班级选择</h3>
  302. <el-select style="width:300px;" v-model="form.classId">
  303. <el-option v-for="item in classInfos" :key="item.id" :label="item.majorName" :value="item.id"></el-option>
  304. </el-select>
  305. <h3>课程选择</h3>
  306. <el-select style="width:300px;" v-model="form.curriculumId">
  307. <el-option v-for="item in curriculumList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  308. </el-select>
  309. <h3>项目选择</h3>
  310. <div class="course-selector">
  311. <div class="course-selector-item" v-for="item in courseInfos" :style="{backgroundImage:getImage(item.imageUrl)}">
  312. <input class="checkCourse" type="checkbox" :checked="item.checked" @change="changeCheckCourse(item.id,$event)" />
  313. <div class="course-title">{{item.name}}</div>
  314. </div>
  315. </div>
  316. </div>
  317. <div v-show="currStep==1" class="knowledge-setting setting-info">
  318. <el-table row-key="id" :data="knowledgeList"
  319. v-loading="loadingTable"
  320. style="width: 100%" height="100%"
  321. highlight-current-row>
  322. <el-table-column prop="name" label="知识点名称" />
  323. <el-table-column prop="durationStudyMin" label="知识点停留时长" >
  324. <template #default="scope">
  325. <el-input-number v-model="durationStudyMins[scope.row.id]"
  326. :min="0"
  327. :max="1000"
  328. controls-position="right"
  329. size="default"
  330. />
  331. </template>
  332. </el-table-column>
  333. </el-table>
  334. </div>
  335. <div v-show="currStep==2" class="defects-setting setting-info">
  336. <div class="defects-title">常见缺陷</div>
  337. <div class="defects-body">
  338. <div class="defects-block" v-for="(item,i) in normalDefectsList">
  339. <div class="defects-item-title-wrap">
  340. <div class="defects-item-title">{{(i+1)+'、'+item.name}}</div>
  341. <input class="defects-item-check" :checked="deffectsCheckeds[item.id]" type="checkbox" @change="changeCheckDeffects(item.id,$event,1)"/>
  342. </div>
  343. <div class="defects-image-wrap">
  344. <img v-if="item.imageUrls!=null" class="defects-image" :src="item.imageUrls[0]"/>
  345. <img v-if="item.imageUrls!=null&&item.imageUrls[1]!=null" class="defects-image" :src="item.imageUrls[1]"/>
  346. </div>
  347. </div>
  348. </div>
  349. <div class="defects-title">其他缺陷</div>
  350. <div class="defects-body">
  351. <div class="defects-block" v-for="(item,i) in otherDefectsList">
  352. <div class="defects-item-title-wrap">
  353. <div class="defects-item-title">{{(i+1)+'、'+item.name}}</div>
  354. <input class="defects-item-check" :checked="deffectsCheckeds[item.id]" type="checkbox" @change="changeCheckDeffects(item.id,$event,2)"/>
  355. </div>
  356. <div class="defects-image-wrap">
  357. <img v-if="item.imageUrls!=null" class="defects-image" :src="item.imageUrls[0]" />
  358. <img v-if="tem.imageUrls!=null&&item.imageUrls[1]!=null" class="defects-image" :src="item.imageUrls[1]" />
  359. </div>
  360. </div>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. </template>
  366. <style scoped>
  367. .task-editor-wrapper {
  368. margin: 1rem;
  369. margin-bottom: 1rem;
  370. height: calc(100% - 2rem);
  371. width: calc(100% - 2rem);
  372. background: #fff;
  373. display: grid;
  374. grid-template-columns: 15rem 1fr;
  375. grid-column-gap: 1rem;
  376. box-sizing: border-box;
  377. color: rgb(117,117,117);
  378. }
  379. .task-editor-steps-wrapper {
  380. display: flex;
  381. flex-direction: column;
  382. justify-content: center;
  383. align-items: center;
  384. box-sizing: border-box;
  385. padding: 0 0 2rem 0;
  386. }
  387. .task-back {
  388. height:6rem;
  389. width:100%;
  390. box-sizing:border-box;
  391. padding:1rem 1rem 2rem 1rem;
  392. display:flex;
  393. align-items:center;
  394. justify-content:start;
  395. cursor:pointer;
  396. }
  397. .task-editor-panel {
  398. height: 100%;
  399. overflow: hidden;
  400. }
  401. .task-step-opts {
  402. height: 10rem;
  403. display: flex;
  404. align-items: center;
  405. justify-content: center;
  406. }
  407. .setting-info {
  408. height:100%;
  409. width:100%;
  410. box-sizing:border-box;
  411. overflow:hidden;
  412. padding:2rem 0;
  413. }
  414. .base-setting {
  415. display: grid;
  416. grid-template-rows:3rem 3rem 3rem 3rem 3rem 3rem 3rem calc(100% - 9rem);
  417. align-items:center;
  418. padding:0 0.5rem;
  419. }
  420. .course-selector {
  421. display: flex;
  422. flex-wrap: wrap;
  423. gap: 2rem;
  424. height:100%;
  425. }
  426. .course-selector-item {
  427. height:15rem;
  428. width:15rem;
  429. color:#fff;
  430. box-shadow:rgba(0,0,0,0.3) 0px 0px 3px;
  431. border-radius:3px;
  432. justify-content:space-between;
  433. flex-flow:column;
  434. overflow:hidden;
  435. display:flex;
  436. background-repeat:no-repeat;
  437. background-size:100% auto;
  438. background-position:center;
  439. }
  440. .course-title {
  441. /* height: 2rem;*/
  442. width:100%;
  443. background: var(--el-color-primary);
  444. color:#fff;
  445. display:flex;
  446. align-items:center;
  447. box-sizing:border-box;
  448. padding:0 0.5rem;
  449. justify-content:center;
  450. }
  451. .checkCourse {
  452. height:2rem;
  453. width:2rem;
  454. border-radius:0;
  455. align-self:end;
  456. margin:1rem 1rem 0 0;
  457. }
  458. .knowledge-setting {
  459. overflow-y: auto;
  460. padding: 2rem 2rem 2rem 0;
  461. }
  462. .defects-setting {
  463. padding:2rem 2rem 2rem 0;
  464. display:grid;
  465. height:100%;
  466. width:100%;
  467. grid-template-rows:3rem 1fr 3rem 1fr;
  468. align-items:center;
  469. }
  470. .defects-title {
  471. font-weight: bold;
  472. background: #F5F7FA;
  473. color: #1D2129;
  474. height:3rem;
  475. line-height:3rem;
  476. font-size:1.2rem;
  477. padding:0 1rem;
  478. }
  479. .defects-body {
  480. display: flex;
  481. flex-flow: wrap;
  482. overflow: hidden;
  483. overflow-y: auto;
  484. grid-gap: 2rem;
  485. height:100%;
  486. width:100%;
  487. box-sizing:border-box;
  488. padding:2rem 0;
  489. }
  490. .defects-block {
  491. width: 18rem;
  492. height: 12rem;
  493. box-shadow: rgba(0,0,0,0.1) 0px 0px 2px;
  494. border: 1px solid #E5E6EB;
  495. border-radius:3px;
  496. display:grid;
  497. grid-template-rows:3rem 1fr;
  498. }
  499. .defects-item-title-wrap {
  500. display: flex;
  501. justify-content: space-between;
  502. align-items: center;
  503. padding: 0 1rem;
  504. border-bottom: 1px solid #E5E6EB;
  505. }
  506. .defects-item-title {
  507. font-weight:bold;
  508. font-size:1.1rem;
  509. }
  510. .defects-item-check {
  511. height:1.5rem;
  512. width:1.5rem;
  513. }
  514. .defects-image-wrap {
  515. padding:1rem;
  516. display:grid;
  517. grid-template-columns:1fr 1fr;
  518. grid-gap:1rem;
  519. }
  520. .defects-image {
  521. background:#ccc;
  522. height:100%;
  523. width:100%;
  524. overflow:hidden;
  525. }
  526. </style>