knowledgePoints.vue
7.81 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
<template>
<el-container class="default-knowledge-body" v-loading="loading">
<el-main class="knowledge-main">
<div>
<el-row :gutter="20" class="knowledge-row" v-if="false">
<el-col :span="8" style="float: right;">
<div class="grid-content bg-purple">
<el-input placeholder="搜索知识点" v-model="knowledgKeyword">
<el-button slot="append" @click="_knowledgSerach" icon="el-icon-search" />
</el-input>
</div>
</el-col>
</el-row>
<el-row :gutter="20" class="knowledge-row">
<el-col>
<label class="input-tags-label">已设置知识点:</label>
<div class="input-tags">
<el-tag class="knowledgTag" v-for="(knowledg, knowledgIndex) in knowledgValues"
:key="knowledgIndex" closable @close="_knowledgRemove(knowledgIndex)">
{{ knowledg[knowledg.length - 1] }}
</el-tag>
</div>
</el-col>
</el-row>
<el-row :gutter="20" class="knowledge-row" style="margin:0px !important;">
<el-cascader-panel :value="knowledgValues" ref="knowledgeCascader" @change="_knowledgeChange"
@expand-change="_knowledgeExpandChange" :props="knowledgeOptions" :options="knowledgeList"
:default-expanded-keys="[]" placeholder="请选择知识点" :filterable="true" />
</el-row>
</div>
</el-main>
<el-footer class="knowledge-footer">
<el-button @click="_opration('cancel')">取 消</el-button>
<el-button type="primary" @click="_opration('confirm')">确 定</el-button>
</el-footer>
</el-container>
</template>
<script>
export default {
props: {
knowledges: "",
///学段
sectionName: "",
///学科
subjectName: "",
},
data() {
return {
loading: false,
///级联选择框参数
knowledgeOptions: {
//多选
multiple: true,
//父子节点不关联
checkStrictly: true
},
knowledgMaxLength: 5,
knowledgeData: [],
knowledgeList: [],
knowledgKeyword: "",
knowledgValues: [],
}
},
methods: {
_opration(opration) {
var outKnowledges = this.knowledgValues.map(mo => {
return '#' + mo.join('#');
});
this.$emit('opration', {
opration: opration,
knowledges: outKnowledges
});
},
_knowledgeChange(values) {
if (values.length > this.knowledgMaxLength) {
this.$message.error(`最多只能选择 ${this.knowledgMaxLength} 项`);
this.$nextTick(() => {
this.$refs.knowledgeCascader.checkedValue = this.knowledgValues;
this.$refs.knowledgeCascader.checkedNodePaths = this.$refs.knowledgeCascader.checkedNodePaths.splice(5, 1)
this.$refs.knowledgeCascader.syncMultiCheckState();
this.$refs.knowledgeCascader.syncActivePath();
})
this._clearNotChecked();
return;
}
this._clearNotChecked();
this.knowledgValues = values;
},
_knowledgeExpandChange(values) {
this._clearNotChecked();
},
_knowledgRemove(knowledgIndex) {
this.knowledgValues.splice(knowledgIndex, 1);
this.$refs.knowledgeCascader.checkedValue = this.knowledgValues;
this.$refs.knowledgeCascader.syncMultiCheckState();
},
_knowledgSerach() {
},
_knowledgFilter(data, query) {
return data
.map((item) => {
const children = item.children ? this._knowledgFilter(item.children, query) : [];
if (children.length || item.value.toLowerCase().indexOf(query) >= 0) {
return {
...item,
children: children.length ? children : undefined,
};
}
return null;
})
.filter((item) => item);
},
async _knowledgInit() {
var { data, info, status } = await this.$request.gKnowledge(this.$props.sectionName, this.$props.subjectName);
if (status != 0) {
this.$message.error(info);
return;
}
this.knowledgeData = [...data];
this.knowledgeList = [...this.knowledgeData]
if (this.$props.knowledges && this.$props.knowledges.length >= 1) {
var propsKnowledges = this.$props.knowledges?.split(',').map(item => item?.split('#').filter(fdl => fdl?.length >= 1));
this.knowledgValues = propsKnowledges;
}
},
_clearNotChecked() {
this.$nextTick(() => {
if (!this.$refs.knowledgeCascader.$el) return;
var checkedPath = this.$refs.knowledgeCascader.$el.querySelectorAll('.in-checked-path');
for (var ofi = 0; ofi < checkedPath.length; ofi++) {
var checkPath = checkedPath[ofi];
var checkPathIsChecked = checkPath.querySelectorAll('.is-checked');
if (checkPathIsChecked.length < 1) {
checkPath.classList.remove('in-checked-path');
}
}
});
}
},
mounted() {
},
async created() {
this.loading = true;
await this._knowledgInit();
this.loading = false;
this.$nextTick(() => {
if (!this.$refs.knowledgeCascader.menus) return;
this.$refs.knowledgeCascader.menus = [this.$refs.knowledgeCascader.menus[0]]
})
this._clearNotChecked();
}
}
</script>
<style lang="scss">
.default-knowledge-body {
padding: 0px !important;
.knowledge-footer {
text-align: right;
padding: 10px;
}
.el-main {
padding: 0px !important;
}
.knowledge-main {
width: 100%;
padding: 0px 10px !important;
.el-cascader-node.in-active-path {
background: #cddbe8 !important;
}
.el-cascader-node.in-active-path:not(.in-checked-path) {
color: #606266 !important;
}
.el-cascader-node.is-selectable.in-active-path {
background: #ecf5ff;
}
.el-cascader-panel {
width: 100% !important;
}
.input-tags-label {
float: left;
line-height: 40px;
margin-right: 12px;
}
.input-tags {
border: 1px solid #DCDFE6;
min-height: 40px;
margin-left: 130px;
border-radius: 5px;
padding: 5px 5px 0px 5px;
}
.knowledge-row {
.knowledgTag {
margin-right: 5px;
margin-bottom: 5px;
}
margin-bottom: 10px;
.el-input-group__append {
background-color: transparent !important;
border-left: none !important;
padding-right: 10px !important;
.el-icon-search {
font-size: 20px;
}
}
.el-input__inner {
border-right: none !important;
}
}
}
}
</style>