course.vue
16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<!-- 课程列表 -->
<template>
<d2-container class="evaluation-wrap">
<div class="header" slot="header">
<d2-search
ref="showSearch"
class="show-search"
:search-form="searchForm"
:label-width="'85px'"
:form-data="showFormData"
>
</d2-search>
<div class="up-btns">
<el-button size="small" type="primary" @click="handleSearch">
查询
</el-button>
<el-button size="small" @click="handleReset"> 重置 </el-button>
</div>
</div>
<div class="d2-container-content">
<d2-table-header>
<span>
<auth-button
category="Button"
:show-btn-ids="['9190702', '9190703', '9190709']"
/>
</span>
</d2-table-header>
<!-- :get-list-api="getListApi" -->
<d2-table
ref="table"
:get-list-api="getListApi"
:search-form="searchFormSearch"
:table-params="tableParams"
:sortObj="sortObj"
:maxHeight="370"
:before-search-fn="beforeSearchFn"
>
<!-- 课程标题 -->
<div slot="titleHtml" slot-scope="scope">
<span v-if="scope.scope.title.length < 28">{{
scope.scope.title.slice(0, 28)
}}</span>
<div v-else>
<el-tooltip
class="item"
effect="dark"
:content="scope.scope.title"
placement="top-start"
>
<span> {{ scope.scope.title.slice(0, 28) }}...</span>
</el-tooltip>
</div>
</div>
<!-- 课程状态 -->
<div slot="statusHtml" slot-scope="scope">
<div class="online-status">
<span
class="dot"
:style="{
background: getStatusColor(
scope && scope.scope && scope.scope.courseStatus,
'courseStatusOptMap'
)
}"
></span>
{{
getStatusItem(
baseData,
"courseStatusOpt",
scope.scope,
"courseStatus"
)
}}
</div>
</div>
<div slot="auth-button" slot-scope="scope">
<!-- 编辑 -->
<span style="margin-right: 10px">
<auth-button :data="scope.scope" :show-btn-ids="['9190705']" />
</span>
<!-- 数据 -->
<span style="margin-right: 10px">
<auth-button :data="scope.scope" :show-btn-ids="['9190704']" />
</span>
</div>
</d2-table>
</div>
<glsk-form-dialog
v-if="isClassifyVisible"
ref="addClassify"
:selectVisible="isClassifyVisible"
:dialogConfig="isClassifyDialogConfig"
label-width="150px"
defaultWidth="290px"
:formRules="isClassifyRules"
:editData="isClassifyForm"
:editFormData="isClassifyFormData"
:baseData="baseData"
@handleClose="isClassifyDialogVisible"
@handleConfirm="handleClassifyConfirm"
:slotArr="slotArr"
:appendToBody="true"
>
<template #systematicNameHtml>
<el-cascader
v-model="isClassifyForm.classifyValue"
:options="treeData"
@change="handleChange"
:props="treeProps"
clearable
></el-cascader>
</template>
</glsk-form-dialog>
</d2-container>
</template>
<script>
import {
queryCoursePage,
synCourseData,
batchUpdateCourseCategory,
getOrganizationList,
exportCourse
} from "@/api/serviceCentre"
import {
courseFileTypeOpt,
courseStatusOpt,
courseStatusOptMap
} from "@/common/constants.js"
import { Util, deepClone } from "@/common/util"
export default {
data() {
return {
slotArr: ["systematicNameHtml"],
isClassifyVisible: false,
isClassifyDialogConfig: {
title: "批量分类",
okText: "保存"
},
isClassifyRules: {
classifyValue: [
{ required: true, message: "请选择分类名称", trigger: "change" }
]
},
isClassifyForm: {
courseId: "",
classifyValue: []
},
isClassifyFormData: [
{
label: "分类名称",
name: "classifyValue",
addHtml: "systematicNameHtml"
}
],
detailInfo: {},
getListApi: queryCoursePage,
sortObj: {
learnTotal: {
ascending: 0,
descending: 1
},
totalStar: {
ascending: 2,
descending: 3
},
createdTime: {
ascending: 4,
descending: 5
}
},
tableParams: {
listName: "list",
mutiSelectUniqueKey: "id",
mutiSelectName: "mutiSelectIndex",
tableOption: {
width: "170"
},
tableColumns: [
{
label: "课程标题",
prop: "title",
addHtml: "titleHtml",
width: "200px"
},
{
label: "类型",
prop: "courseFileType",
width: "100px",
formatter: (cellValue) => {
return this.getStatusItem(
this.baseData,
"courseFileTypeOpt",
cellValue,
"courseFileType"
)
}
},
{
label: "时长/分钟",
prop: "totalDuration",
width: 140,
formatter: (cellValue) => {
return cellValue.totalDuration || 0
}
},
{
label: "课程状态",
prop: "courseStatus",
minWidth: 120,
addHtml: "statusHtml",
isPopConfig: {
text: "课程状态来自北森系统的课程管理,若课程状态为“已下架”,则不会展示在学习中心。"
}
},
{
label: "课程分类",
prop: "categoryName",
width: 160
},
{
label: "所属部门",
prop: "organizationName",
width: 120
},
{
label: "学习人数",
prop: "learnTotal",
sortable: "custom",
width: 120,
formatter: (cellValue) => {
return cellValue.learnTotal || 0
}
},
{
label: "评分",
prop: "totalStar",
sortable: "custom",
width: 120,
formatter: (cellValue) => {
return cellValue.totalStar || 0
}
},
{
label: "创建人",
prop: "createdBy",
width: 160
},
{
label: "创建时间",
prop: "createdTime",
sortable: "custom",
width: "150px",
formatter: (row, column) => {
return Util.dateFormate(row.createdTime, "YYYY-MM-DD HH:mm:ss")
}
}
]
},
searchFormSearch: {},
searchForm: {
title: "",
courseFileType: "",
courseStatus: "",
createdBy: "",
createdDate: [],
organizationV2Id: ""
},
showFormData: [
{
label: "课程标题",
name: "title",
type: "input",
isClear: true
},
{
label: "类型",
name: "courseFileType",
type: "select",
isClear: true,
optionList: [],
optionId: "confId",
optionLabel: "confValue",
optionsName: "courseFileTypeOpt"
},
{
label: "课程状态",
name: "courseStatus",
type: "select",
isClear: true,
optionList: [],
optionId: "confId",
optionLabel: "confValue",
optionsName: "courseStatusOpt"
},
{
label: "所属部门",
name: "organizationV2Id",
type: "select",
isClear: true,
optionList: [],
optionId: "oid",
optionLabel: "name",
optionsName: "organizationOpt"
},
{
label: "创建人",
name: "createdBy",
type: "input",
isClear: true
},
{
label: "创建时间",
name: "createdDate",
type: "datePicker",
isClear: true
}
],
baseData: {
courseFileTypeOpt: deepClone(courseFileTypeOpt),
courseStatusOptMap: deepClone(courseStatusOptMap),
organizationOpt: [],
courseStatusOpt: deepClone(courseStatusOpt)
}
}
},
props: {
list: {
type: Array,
default: () => []
},
courseCategoryId: {
type: String,
default: ""
}
},
computed: {
treeData() {
const normalize = (arr) =>
(arr || []).map((it) => {
const children = normalize(it.children || [])
const node = {
id: it.id,
name: it.categoryName || "",
parentId: it.parentId
}
if (children.length) {
node.children = children
}
return node
})
const nodes = normalize(this.list)
const result = []
nodes.forEach((node) => {
if (node.name === "未分类") {
if (node.children && node.children.length) {
result.push(...node.children)
}
} else {
result.push(node)
}
})
return result
},
treeProps() {
return {
checkStrictly: true,
label: "name",
children: "children",
value: "id"
}
}
},
watch: {
courseCategoryId(val) {
this.handleSearch()
}
},
mounted() {
this.fetchOnboardingPlans()
},
methods: {
//数据同步
async handleSynchrodata() {
let ok = await synCourseData()
console.log(ok)
if (ok) {
this.$message.success("数据同步成功")
this.handleSearch()
}
},
filterIds() {
let ids = []
if (this.$refs.table.mutiSelectArr.mutiSelectIndex) {
this.$refs.table.mutiSelectArr.mutiSelectIndex.forEach((item) => {
ids.push(item.courseId)
})
}
return ids
},
handleClassification() {
if (!this.filterIds().length) {
this.$message.error("请选择要批量分类的课程")
return
}
this.isClassifyDialogConfig.title = "批量分类"
this.isClassifyForm.classifyValue = []
this.isClassifyVisible = !this.isClassifyVisible
},
handleChange(val) {},
isClassifyDialogVisible() {
this.isClassifyForm.classifyValue = []
this.isClassifyVisible = !this.isClassifyVisible
},
async handleClassifyConfirm() {
try {
let [parentId, id] = this.isClassifyForm.classifyValue
if (this.isClassifyForm.classifyValue.length < 2) {
id = parentId
parentId = 0
}
let params = {
parentId,
id,
courseIdList: this.filterIds().length
? this.filterIds()
: [this.isClassifyForm.courseId]
}
let result = await batchUpdateCourseCategory(params)
if (result) {
this.$message.success("操作成功")
this.isClassifyVisible = false
this.handleSearch()
}
} catch (e) {
console.log(e)
// this.$message.error(e.message)
this.isClassifyVisible = false
}
},
//数据
handleDataView(row) {
row.activeName = "dataView"
row.pageId = "courseId" + row.courseId
row.title = row.title
this.$emit("openWindow", row)
},
// 在树中查找某分类 id 的路径,用于级联回显
findPathById(nodes, targetId) {
const path = []
const dfs = (arr) => {
for (const n of arr || []) {
path.push(n.id)
if (n.id === targetId) return true
if (n.children && dfs(n.children)) return true
path.pop()
}
return false
}
return dfs(nodes) ? path : []
},
// 编辑时回显
handleEdit(row) {
this.isClassifyDialogConfig.title = "编辑课程分类"
this.isClassifyForm.courseId = row.courseId
// 目标分类 id(优先用 row.categoryId)
const targetId = row.categoryId || row.id
// 尝试在树中找到完整路径
const path = this.findPathById(this.treeData, targetId)
// 找到则用完整路径;否则使用二级结构的兜底
this.isClassifyForm.classifyValue = path.length
? path
: [row.parentId, targetId].filter((v) => v != null)
this.isClassifyVisible = true
},
getOptionsList(that, formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = that[formName].find((k) => k.name == refreshSigle)
var index = that[formName].findIndex((k) => k.name == refreshSigle)
that.$set(
that[formName][index],
"optionList",
deepClone(that.baseData[item.optionsName])
)
if (
hasAll &&
that.baseData[item.optionsName].length &&
that.baseData[item.optionsName][0][
that[formName][index].optionLabel
] !== "全部"
) {
const temp = {}
temp[that[formName][index].optionId] = ""
temp[that[formName][index].optionLabel] = "全部"
that[formName][index].optionList.unshift(temp)
}
} else {
that[formName].forEach((item, index) => {
if (
item.type === "select" &&
that.baseData[item.optionsName]?.length
) {
that.$set(
that[formName][index],
"optionList",
deepClone(that.baseData[item.optionsName])
)
if (
hasAll &&
that.baseData[item.optionsName].length &&
that.baseData[item.optionsName][0][
that[formName][index].optionLabel
] !== "全部"
) {
const temp = {}
temp[that[formName][index].optionId] = ""
temp[that[formName][index].optionLabel] = "全部"
that[formName][index].optionList.unshift(temp)
}
}
})
}
},
async fetchOnboardingPlans() {
try {
const [organizationOpt] = await Promise.all([getOrganizationList()])
// 处理返回的数据
this.baseData.organizationOpt = organizationOpt.list
this.getOptionsList(this, "showFormData", true)
} catch (error) {
console.error(error)
}
},
getStatusColor(status, optKey) {
if (status === null || status === undefined) return "#C0C4CC"
const map = (this.baseData && this.baseData[optKey]) || {}
return map[status] || "#C0C4CC"
},
getStatusItem(baseData, optKey, row, rowKey) {
if (!baseData || !baseData[optKey] || !row) return null
let item = baseData[optKey].find((item) => item.confId == row[rowKey])
return (item && item.confValue) || "-"
},
// 导出列表
handleCourseExport() {
var params = this.getParams()
params.orderByType = this.$refs.table.orderByType
params.currentPage = 1
exportCourse(params).then((res) => {
this.$open(res)
})
},
getParams() {
let params = deepClone(this.searchForm)
// 申请时间
if (params?.createdDate?.length) {
let [start, end] = params.createdDate
params.createTimeStart = Util.dateFormate(start, "YYYY-MM-DD HH:mm:ss")
params.createTimeEnd = Util.dateFormate(end, "YYYY-MM-DD") + " 23:59:59"
}
params.courseCategoryId = this.courseCategoryId
delete params.createdDate
return params
},
beforeSearchFn() {
return new Promise((resolve, reject) => {
this.searchFormSearch = this.getParams()
resolve()
})
},
handleSearch() {
this.page = this.$options.data.call(this).page
this.$refs.table.refreshTable(true, true)
},
handleReset() {
this.searchForm = this.$options.data.call(this).searchForm
this.courseCategoryId = ""
this.handleSearch()
}
}
}
</script>
<style scoped lang="scss">
.online-status {
display: flex;
justify-content: center;
align-items: center;
.dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-right: 8px;
}
}
</style>