123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <template>
- <div class="fill-drag">
- <!-- 选项 -->
- <div class="fill-drag-options">
- <draggable
- v-model="curQue.options"
- group="option"
- animation="300"
- class="draggable-options"
- :sort="false"
- ghost-class="draggable-options-ghost"
- :disabled="isAnswerMode"
- :move="onMove"
- >
- <span
- v-for="({ text, imageList }, i) in curQue.options"
- :key="`option-${i}`"
- class="drag-option"
- :style="{
- cursor: `${isAnswerMode ? 'default' : 'pointer'}`,
- padding: `${imageList.length > 0 ? '0px' : '8px'}`
- }"
- >
- <template v-if="imageList.length > 0">
- <el-image :src="imageList[0].url" fit="fill" />
- </template>
- <template v-else>
- {{ text }}
- </template>
- </span>
- </draggable>
- </div>
- <!-- 填空 -->
- <div class="fill-drag-fills">
- <div
- v-for="(fill, i) in curQue.fills"
- :key="`fill-${i}`"
- class="drag-fill"
- :data-serial="i + 1"
- >
- <!-- 偏旁 -->
- <span class="drag-fill-space active" v-text="fill.side" />
- <div class="drag-fill-container">
- <span
- v-for="(drag, j) in fill.dragList"
- :key="j"
- :class="[
- 'drag-fill-space',
- `${drag.fillList.length > 0 ? 'active' : ''}`
- ]"
- >
- <draggable
- v-model="drag.fillList"
- class="draggable-fill"
- group="option"
- animation="300"
- :sort="false"
- :data-fill="i"
- :data-space="j"
- :disabled="isAnswerMode"
- :move="onMoveTo"
- @change="changeFill"
- >
- <span
- v-for="{ text, imageList } in drag.fillList"
- :key="text"
- :style="{
- cursor: `${isAnswerMode ? 'default' : 'pointer'}`,
- padding: `${imageList.length > 0 ? '0px' : '8px'}`
- }"
- >
- <template v-if="imageList.length > 0">
- <el-image :src="imageList[0].url" fit="fill" />
- </template>
- <template v-else>
- {{ text }}
- </template>
- </span>
- </draggable>
- </span>
- </div>
- <span
- class="drag-delete"
- :style="{
- cursor: `${isAnswerMode ? 'default' : 'pointer'}`
- }"
- @click="emptyFill(i)"
- >
- <el-image :src="require('../../../assets/NPC/delete-24.png')" />
- </span>
- </div>
- </div>
- </div>
- </template>
- <script>
- import draggable from "vuedraggable";
- export default {
- components: { draggable },
- props: {
- curQue: {
- type: Object,
- required: true
- },
- themeColor: {
- type: String,
- required: true
- }
- },
- data() {
- return {
- isAnswerMode: false,
- curDrag: {
- fillIndex: 0,
- spaceIndex: 0
- }
- };
- },
- created() {
- const Bookanswer = this.curQue.Bookanswer;
- if (Bookanswer) {
- this.isAnswerMode = true;
- Bookanswer.dragList.forEach(({ fillIndex, spaceIndex, ...data }) => {
- this.curQue.fills[fillIndex].dragList[spaceIndex].fillList = [
- { ...data }
- ];
- });
- } else {
- let Bookanswer = {
- dragList: []
- };
- this.$set(this.curQue, "Bookanswer", Bookanswer);
- }
- },
- methods: {
- onMove(e) {
- if (e.relatedContext.component.realList.length > 0) return false;
- let { fill, space } = e.to.dataset;
- this.curDrag = {
- fillIndex: fill,
- spaceIndex: space
- };
- return true;
- },
- onMoveTo(e) {
- if (
- e.to.classList.contains("draggable-fill") &&
- e.relatedContext.component.realList.length > 0
- ) { return false; }
- let { fill, space } = e.from.dataset;
- this.curDrag = {
- fillIndex: fill,
- spaceIndex: space
- };
- },
- changeFill({ added, removed }) {
- if (added) {
- this.curQue.Bookanswer.dragList.push({
- ...this.curDrag,
- ...added.element
- });
- }
- if (removed) {
- this.curQue.Bookanswer.dragList = this.curQue.Bookanswer.dragList.filter(
- ({ fillIndex, spaceIndex }) => {
- let { fillIndex: fIndex, spaceIndex: sIndex } = this.curDrag;
- if (fillIndex === fIndex && spaceIndex === sIndex) return false;
- return true;
- }
- );
- }
- },
- emptyFill(i) {
- if (this.isAnswerMode) return;
- this.curQue.fills[i].dragList.forEach(({ fillList }) => {
- if (fillList.length > 0) {
- this.curQue.options.push(...fillList.splice(0, 1));
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- $image-size: 64px;
- .fill-drag {
- width: 100%;
- color: #000;
- margin-bottom: 16px;
- %drag-option {
- width: $image-size;
- height: $image-size;
- font-size: 48px;
- font-family: "FZJCGFKTK";
- border-radius: 8px;
- text-align: center;
- background-size: $image-size $image-size;
- overflow: hidden;
- .el-image {
- width: $image-size;
- height: $image-size;
- }
- }
- &-options {
- width: 100%;
- background-color: #f7f7f7;
- border: 1px solid #dedede;
- border-radius: 8px;
- padding: 24px;
- .draggable-options {
- display: flex;
- flex-wrap: wrap;
- min-height: 64px;
- column-gap: 16px;
- row-gap: 24px;
- .drag-option {
- @extend %drag-option;
- background-image: url("../../../assets/NPC/tian-zige.png");
- }
- }
- // 拖拽插件,占位符样式,需要加 !important
- .draggable-options-ghost {
- width: $image-size !important;
- height: $image-size !important;
- font-size: 48px !important;
- font-family: "FZJCGFKTK" !important;
- border-radius: 8px !important;
- text-align: center !important;
- background-size: $image-size $image-size !important;
- background-image: url("../../../assets/NPC/tian-zige.png") !important;
- }
- }
- &-fills {
- margin-left: 24px;
- .drag-fill {
- margin-top: 24px;
- display: flex;
- flex-wrap: no-wrap;
- align-items: center;
- column-gap: 16px;
- &::before {
- content: attr(data-serial) ".";
- display: inline-block;
- height: 16px;
- width: 16px;
- font-size: 16px;
- margin-right: 16px;
- }
- .drag-fill-container {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- column-gap: 16px;
- row-gap: 12px;
- }
- &-space {
- @extend %drag-option;
- min-width: 64px;
- background-image: url("../../../assets/NPC/tian-zige-noactive.png");
- &.active {
- background-image: url("../../../assets/NPC/tian-zige.png");
- }
- }
- .drag-delete {
- flex: 1;
- padding-right: 16px;
- .el-image {
- float: right;
- width: 24px;
- height: 24px;
- }
- }
- .draggable-fill {
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- column-gap: 16px;
- row-gap: 12px;
- }
- }
- }
- }
- </style>
|