review 清理,变量方法名修改

This commit is contained in:
yuebenshan committed 2023-02-14 22:01:11 +08:00
1 parent 5d4aac843b
commit 47c871a740
10 files changed
+524 -3088

No files matched your search

@@ -1,414 +0,0 @@
<template id="form-item-list-generator">
<v-card color="#f5f8fa" :class="{'d-flex': !isMobile, 'form-item-list-generator-content': !isMobile}">
<v-card :style="{'width': isMobile ? '100%' : '300px'}"
:class="{'pa-4': !isMobile, 'pa-2': isMobile, 'mr-6': !isMobile}">
<div class="left-component-item-title" :style="{'white-space': 'nowrap'}">
<v-icon>mdi-puzzle-outline</v-icon>
<span style="transform: translateY(2px); display: inline-block;">组件</span>
</div>
<draggable
:group="{ name: 'componentGroup', pull: 'clone', put: false }"
:list="componentList"
draggable=".left-component-item"
:clone="cloneComponent"
@end="leftComponentDraggableOnEnd">
<div class="left-component-item"
v-for="(component, index) in componentList" :key="index"
@click="addFormItem(component)">
<div class="left-component-item-body">
<v-icon small class="mr-1">{{ component.icon }}</v-icon>
{{ component.title }}
</div>
</div>
</draggable>
</v-card>
<v-card class="formItemList py-10 pl-4 pr-4" style="position: relative;">
<v-btn small color="error" @click.stop="emptyCanva" class="mr-2 mt-2"
style="position: absolute; right: 8px; top: 0;">
<span>重置</span>
</v-btn>
<draggable
v-if="formItemList.length > 0"
:list="formItemList"
:animation="300"
group="componentGroup">
<v-hover v-for="(formItem, index) in formItemList" :key="index" v-slot:default="{ hover }">
<v-card
@click.native="formItemSelect(formItem.id)"
:elevation="hover ? 12 : 2"
:class="['my-2', selectedFormItemId === formItem.id && !hover ? 'formItem-selected' : 'formItem-body']"
style="cursor: move"
dense>
<v-list-item>
<v-list-item-content v-if="formItem.component.type === 'singleSelect'">
<v-radio-group :disabled="true" :label="(index+1) + '. ' + formItem.component.outline">
<v-radio hide-details v-for="(option, optionIndex) in formItem.component.property.selectOptionList"
:key="optionIndex" :label="option.value" :value="option.value"></v-radio>
</v-radio-group>
</v-list-item-content>
<v-list-item-content v-if="formItem.component.type === 'multipleSelect'">
<v-list-item-title class="formItem-title">{{ index + 1 }}. {{
formItem.component.outline
}}
</v-list-item-title>
<div v-for="(option, optionIndex) in formItem.component.property.selectOptionList" :key="optionIndex">
<v-checkbox hide-details style="margin-top: 0px;" :disabled="true" :label="option.value" hide-details
color="red"></v-checkbox>
</div>
</v-list-item-content>
<v-list-item-content v-if="formItem.component.type === 'textarea'">
<v-textarea dense outlined placeholder="请输入答案" hide-details :disabled="true" :rows="4"
:label="(index+1) + '. ' + formItem.component.outline"/>
</v-list-item-content>
<v-list-item-content v-if="formItem.component.type === 'input'">
<v-text-field class="jh-v-input" dense outlined :label="(index+1) + '. ' + formItem.component.outline"
:disabled="true"></v-text-field>
</v-list-item-content>
<v-list-item-action v-if="selectedFormItemId === formItem.id" class="justify-start">
<v-btn x-small icon @click.stop="formItemCopy(index, formItem)">
<v-icon color="primary">mdi-content-duplicate</v-icon>
</v-btn>
<v-btn x-small icon @click.stop="formItemDelete(formItem.id)">
<v-icon color="error">mdi-close-box</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-card>
</v-hover>
</draggable>
<v-row v-else align="center" justify="center" class="ma-0 pa-0" style="width: 100%;">
<v-card height="100" class="ma-12" width="100%" color="#f5f8fa" style="border: 1px dashed #333333">
<draggable :list="[]" :animation="300" group="componentGroup" style="position: relative; height: 100%;">
<v-card-text class="text-center title draggable-placeholder">
从左侧拖入或点选组件进行表单设计
</v-card-text>
</draggable>
</v-card>
</v-row>
</v-card>
<v-card :style="{'width': isMobile ? 'auto' : '300px'}" class="pa-4" :class="{'ml-6': !isMobile}">
<div class="property-title">
<v-icon>mdi-application-edit-outline</v-icon>
<span style="transform: translateY(2px); display: inline-block;">组件属性</span>
</div>
<div v-if="selectCanvaIndex >= 0 && formItemList[selectCanvaIndex]">
<v-card class="mt-5" flat
v-if="formItemList[selectCanvaIndex].component.type === 'singleSelect' || formItemList[selectCanvaIndex].component.type === 'multipleSelect'">
<v-row no-gutters>
<v-col cols="12">
<v-text-field class="jh-v-input mr-2" dense filled single-line prefix="标题: " color="success"
v-model="formItemList[selectCanvaIndex].component.outline"></v-text-field>
<div style="display: flex; flex-direction: row;justify-content: space-between; align-items: center;">
<v-subheader class="pa-0">选项列表</v-subheader>
<v-btn icon
@click.stop="propertyAddOption(formItemList[selectCanvaIndex].component.property.selectOptionList.length)">
<v-icon dark color="grey lighten-1">mdi-plus-box</v-icon>
</v-btn>
</div>
<v-list class="propertyList" dense style="max-height: 300px; overflow-y: auto;">
<v-list-item
class="pa-0"
v-for="(option, index) in formItemList[selectCanvaIndex].component.property.selectOptionList"
:key="index">
<v-list-item-content>
<v-text-field
v-model="option.value"
prefix="选项:"
color="success"
filled single-line
dense
hide-details
clearable
placeholder="请输入选项"/>
</v-list-item-content>
<v-list-item-action class="ml-2">
<v-btn icon @click.stop="propertyDeleteOption(index)">
<v-icon color="grey lighten-1" dark>mdi-delete</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
</v-col>
</v-row>
</v-card>
<v-card class="mt-5" flat v-if="formItemList[selectCanvaIndex].component.type === 'textarea'">
<v-text-field class="jh-v-input" dense filled single-line label="多行文本"
v-model="formItemList[selectCanvaIndex].component.outline"></v-text-field>
</v-card>
<v-card class="mt-5" flat v-if="formItemList[selectCanvaIndex].component.type === 'input'">
<v-text-field class="jh-v-input" dense filled single-line label="单行文本"
v-model="formItemList[selectCanvaIndex].component.outline"></v-text-field>
</v-card>
</div>
</v-card>
</v-card>
</template>
<script src="//cdn.jsdelivr.net/npm/sortablejs@1.8.4/Sortable.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js"></script>
<script>
// 1. v-main 滚动条
// 2. v-navigation-drawer 小屏幕 不要关闭
Vue.component("form-item-list-generator", {
template: '#form-item-list-generator',
vuetify: new Vuetify(),
name: 'form-item-list-generator',
props: {
formItemList: {
type: Array,
default: [],
required: true,
},
},
data: () => ({
componentList: [
{title: '单行文本', type: 'input', outline: '单行文本', property: {}, icon: 'mdi-form-textarea'},
{title: '多行文本', type: 'textarea', outline: '多行文本', property: {}, icon: 'mdi-form-textarea'},
{
title: '单选',
type: 'singleSelect',
outline: '单选',
property: {selectOptionList: []},
icon: 'mdi-checkbox-marked-circle'
},
{
title: '多选',
type: 'multipleSelect',
outline: '多选',
property: {selectOptionList: []},
icon: 'mdi-checkbox-marked'
},
],
tempComponent: null,
// 当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。
// 对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与 C 语言的 strstr() 以及 Java 的 indexOf() 定义相符。
// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
// `,
// property: {}, icon: 'mdi-checkbox-marked-circle'
// },
// formItemData: {}
// }
// ],
selectedFormItemId: null,
rightPanels: [0, 1, 2, 3, 4],
}),
computed: {
selectCanvaIndex() {
const index = this.formItemList.findIndex(item => item.id === this.selectedFormItemId);
return index;
},
isMobile() {
return window.innerWidth < 600;
},
},
mounted() {
},
destroyed() {
},
watch: {},
async created() {
},
methods: {
cloneComponent(component) {
this.tempComponent = component;
},
leftComponentDraggableOnEnd(event) {
if (event.from !== event.to) {
const newIndex = event.newIndex;
this.addFormItem(this.tempComponent, newIndex);
}
this.tempComponent = null;
},
addFormItem(component, targetIndex) {
const {type} = component;
const formItem = {
id: `${type}_${this.uuid(8)}`,
component: _.cloneDeep(component)
};
if (!this.formItemList) {
this.formItemList = [];
}
if (targetIndex > -1) {
this.formItemList.splice(targetIndex, 0, formItem);
} else {
this.formItemList.push(formItem);
}
},
formItemSelect(id) {
this.selectedFormItemId = id;
},
formItemCopy(index, formItem) {
const newFormItem = _.cloneDeep(formItem);
newFormItem.id = `${newFormItem.component.type}_${this.uuid(8)}`,
this.formItemList.splice(index + 1, 0, newFormItem);
},
emptyCanva() {
this.formItemList.splice(0, this.formItemList.length);
},
formItemDelete(id) {
const index = this.formItemList.findIndex((item) => item.id === id);
if (index > -1) {
this.formItemList.splice(index, 1);
}
},
propertyAddOption(index) {
this.formItemList[this.selectCanvaIndex].component.property.selectOptionList.splice(index, 0, {value: ""});
},
propertyDeleteOption(index) {
this.formItemList[this.selectCanvaIndex].component.property.selectOptionList.splice(index, 1);
},
uuid(t = 21) {
let e = "", r = crypto.getRandomValues(new Uint8Array(t));
for (; t--;) {
let n = 63 & r[t];
e += n < 36 ? n.toString(36) : n < 62 ? (n - 26).toString(36).toUpperCase() : n < 63 ? "_" : "-"
}
;
return e
},
getFormItemList() {
return this.formItemList;
},
},
})
</script>
<style scoped>
.form-item-list-generator-content {
align-items: stretch;
height: 100%;
}
.componentList {
padding: 8px;
box-sizing: border-box;
width: 256px;
overflow-y: auto;
height: 100%;
max-height: 100%;
}
.left-component-item {
width: 100%;
margin: 8px 0;
transition: transform 0ms !important;
}
.left-component-item-title {
font-size: 14px;
color: #222;
margin: 6px 2px;
}
.left-component-item-body {
padding: 8px 10px;
background: #f5f8fa;
font-size: 12px;
cursor: move;
border: 1px dashed #f5f8fa;
border-radius: 3px;
}
.left-component-item-body:hover {
border: 1px dashed #4caf50;
background: #f5f8fa;
color: #4caf50;
}
.left-component-item-body:hover .v-icon {
color: #4caf50;
}
.formItemList {
flex: 1;
overflow-y: auto;
height: 100%;
max-height: 100%;
}
.formItemList .formItem-selected {
border: 1px dashed #4caf50 !important;
background: #e6fde3;
}
.formItem-title {
white-space: normal;
}
.property {
width: 360px;
overflow-y: auto;
max-height: calc(100vh - 105px);
padding: 10px;
}
.property .property-title {
margin-bottom: 10px;
}
.property .v-expansion-panel .v-expansion-panel-header {
min-height: auto;
}
.property .v-expansion-panel-content__wrap {
padding: 0px;
}
.property .v-expansion-panel .v-list-item__action, .v-list-item__avatar, .v-list-item__icon {
display: inline-block;
min-width: 24px;
}
.propertyList::-webkit-scrollbar {
width: 5px;
background: #f5f8fa;
border-radius: 5px;
}
.propertyList::-webkit-scrollbar-thumb {
width: 5px;
background: #606060;
border-radius: 5px;
}
body .theme--light.v-text-field--filled.jh-v-input.black > .v-input__control > .v-input__slot {
background: #e6ebee;
}
.draggable-placeholder {
position: absolute;
left: 0!important;
top: 50%!important;
transform: translateY(-50%)!important;
opacity: 0.3;
}
@media (max-width: 500px) {
.left-component-item {
width: auto;
display: inline-block;
margin: 8px 4px;
transition: transform 0ms !important;
}
.formItemList {
border-top: 2px solid #cccccc !important;
border-bottom: 2px solid #cccccc !important;
border-radius: unset !important;
height: auto;
max-height: none;
overflow: hidden;
}
}
</style>
@@ -1,170 +0,0 @@
<template id="form-item-list-review">
<div class="form-item-list-review-container">
<!-- 单选 -->
<template v-if="formItem.component.type === 'singleSelect'">
<span class="jh-input-label">{{ formItem.component.statement }}</span>
<v-radio-group readonly v-model="formItem.user.answer">
<v-radio
v-for="(option, optionIndex) in formItem.component.selectOptionList" :key="optionIndex"
:label="assignmentOptionKey[optionIndex]+': '+option" :value="option"></v-radio>
</v-radio-group>
</template>
<!-- 多选和填空 -->
<template v-if="['fillBlank', 'multipleSelect'].includes(formItem.component.type)">
<span class="jh-input-label" style="white-space:nowrap !important;" v-if="formItem.component.type === 'fillBlank'">
<template v-for="(blank, blankIndex) in formItem.component.statement" :key="blankIndex">
<span class="fill-blank fill-blank-input" v-if="blank.type === 'input'">{{
formItem.user.answer[blank.id] }}</span>
<span v-else>{{ blank.value }}</span>
</template>
</span>
<span class="jh-input-label" v-else>{{ formItem.component.statement }}</span>
<template v-if="formItem.component.type === 'multipleSelect'">
<template v-for="(option, optionIndex) in formItem.component.selectOptionList" :key="optionIndex">
<v-checkbox
readonly style="margin-top: 0px;" v-model="formItem.user.answer" :value="option"
:label="assignmentOptionKey[optionIndex]+': '+option" hide-details color="red"></v-checkbox>
</template>
</template>
</template>
<!-- 多行文本,问答和markdown -->
<template v-if="['textarea', 'questionAnswer', 'markdown'].includes(formItem.component.type)">
<span class="jh-input-label">{{ formItem.component.statement }}</span>
<template v-if="formItem.component.type === 'markdown'" cols="12">
<md2html :article-content="formItem.user.answer" @complete="isContentLoading = false"></md2html>
</template>
<template v-else cols="12">
<v-textarea readonly dense filled single-line v-model="formItem.user.answer" :rows="5" auto-grow />
</template>
</template>
<!-- 题目组 -->
<template v-if="formItem.component.type === 'questionGroup'">
<span class="jh-input-label">{{ formItem.component.statement }}</span>
<md2html :article-content="formItem.component.markdownContent" @complete="isContentLoading = false">
</md2html>
<form-item-list-review
:form-item-list="formItem.component.itemList" :review-data="reviewData"
:answer-check="answerCheck" />
</template>
<!-- 纯标题 -->
<v-list-item-content v-if="formItem.component.type === 'displayText'">
<p>{{formItem.component.statement}}</p>
</v-list-item-content>
</div>
</template>
<script>
Vue.component("form-item-list-review", {
template: '#form-item-list-review',
vuetify: new Vuetify(),
name: 'form-item-list-review',
props: {
formItem: {
type: Object,
default: () => {
return {};
},
},
reviewData: {
type: Object,
default: () => {
return {};
},
},
answerCheck: {
type: Object,
default: () => {
return {};
},
},
},
data: () => ({
overlay: false,
imgSrc: '',
assignmentOptionKey: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'],
}),
computed: {
isMobile() {
return window.innerWidth < 500;
}
},
destroyed() {
},
watch: {},
created() {
},
methods: {}
})
</script>
<style scoped>
.form-item-list-review-container {
background-color: unset;
}
.form-item-list-review-container .jh-input-label {
white-space: pre-line;
font-weight: bold;
font-size: 16px !important;
}
.form-item-list-review-container audio {
height: 35px;
}
.form-item-list-review-container .audio-box {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
/*.form-item-list-review-container .submit-handle-box {
position: relative;
}
.form-item-list-review-container .submit-handle-box::after {
position: absolute;
width: 1px;
content: '';
background-color: #e0e0e0;
height: 200px;
top: auto;
bottom: auto;
}*/
.student-remark textarea {
color: rgb(0, 172, 37) !important;
}
.fill-blank {
display: inline-block;
}
.fill-blank-input {
padding-left: 10px;
padding-right: 10px;
border-bottom: 2px solid gray;
margin-left: 5px;
margin-right: 5px;
}
.icon-close {
position: fixed;
right: 10px;
top: 5px;
z-index: 50000
}
.icon-download {
position: fixed;
right: 50px;
top: 5px;
z-index: 50000
}
.file-prev-wrap {
overflow: auto;
max-width: 80vw;
max-height: 90vh;
}
</style>
-91
View File
@@ -1,91 +0,0 @@
<template id="tpl-form-design">
<div class="tpl-form-design-container">
<form-item-list-generator
:form-item-list="form"
ref="formItemListGenerator"/>
<!-- <v-navigation-drawer v-model="formItemListPreviewDrawer" fixed temporary bottom width="90%">
<v-toolbar dark class="blue darken-3" dense>
<v-toolbar-title>表单预览</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items>
<v-btn dark text @click="formItemListPreviewDrawer = false">关闭</v-btn>
</v-toolbar-items>
</v-toolbar>
<v-card class="mt-3">
<v-row>
<v-col cols="12" md="6" class="pa-0">
<codemirror v-model="JSON.stringify(formItemList, null, 4)" :options="codemirrorOptions"/>
</v-col>
<v-col cols="12" md="6">
<form-item-list-render :form-item-list="formItemList"></form-item-list-render>
</v-col>
</v-row>
</v-card>
</v-navigation-drawer> -->
</div>
</template>
<script type="module">
Vue.component("tpl-form-design", {
template: "#tpl-form-design",
props: {
form: {
type: Array,
default: () => {
return []
}
}
},
data: () => ({
}),
computed: {
versionList () {
const list = this.articleAssignmentListWithAnswer.map(item => {
return { text: item.version, value: item.version }
})
return list;
},
formItemList () {
let list = []
if (this.articleAssignmentListWithAnswer[this.selectedVersionIndex]) {
list = this.articleAssignmentListWithAnswer[this.selectedVersionIndex].formItemList;
}
return list;
}
},
watch: {
// 每个属性值发生变化就会调用这个函数
form(newVal, oldVal) {
this.saveData(newVal)
},
// 深度监听 属性的变化
deep: true
},
async created() {
},
mounted() {},
methods: {
saveData(newVal) {
// this.$emit('change-structure', this.form);
}
}
})
</script>
<style scoped>
.tpl-form-design-container {
width: 100%;
height: 500px;
max-height: 500px;
overflow-y: auto;
}
@media (max-width: 500px) {
.tpl-form-design-container {
width: 100%;
height: auto;
max-height: none;
overflow-y: hidden;
}
}
</style>