|
@@ -0,0 +1,139 @@
|
|
|
+import { Tag, Image, Button } from 'vant'
|
|
|
+import { defineComponent, nextTick, onMounted, PropType, reactive } from 'vue'
|
|
|
+import { labelOptions } from '../../unit'
|
|
|
+import Draggable from 'vuedraggable'
|
|
|
+import styles from './index.module.less'
|
|
|
+import Sortable from 'sortablejs'
|
|
|
+import deepClone from '@/helpers/deep-clone'
|
|
|
+
|
|
|
+// 单选和多选题
|
|
|
+export default defineComponent({
|
|
|
+ name: 'choice-question',
|
|
|
+ props: {
|
|
|
+ value: {
|
|
|
+ type: [String, Number, Array],
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ type: {
|
|
|
+ type: String as PropType<'radio' | 'checkbox'>,
|
|
|
+ default: 'radio'
|
|
|
+ },
|
|
|
+ answers: {
|
|
|
+ type: Object,
|
|
|
+ default: {}
|
|
|
+ },
|
|
|
+ /* 只读 */
|
|
|
+ readOnly: {
|
|
|
+ type: Boolean,
|
|
|
+ default: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ emits: ['update:value'],
|
|
|
+ setup(props, { emit }) {
|
|
|
+ const state = reactive({
|
|
|
+ domId: 'draggableContainer' + +new Date(),
|
|
|
+ drag: false,
|
|
|
+ sortable: null as any,
|
|
|
+ list: [] as any,
|
|
|
+ options: [
|
|
|
+ {
|
|
|
+ index: 1,
|
|
|
+ value: 'Sol'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ index: 2,
|
|
|
+ value: 'Sal'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ index: 3,
|
|
|
+ value: 'La'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ index: 4,
|
|
|
+ value: 'Si'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+
|
|
|
+ // const onSelect = (item: any) => {
|
|
|
+ // if (props.type === 'checkbox') {
|
|
|
+ // // 判断是否已选过
|
|
|
+ // const value: any = props.value
|
|
|
+ // if (value.includes(item.index)) {
|
|
|
+ // const index = value.findIndex((v: any) => v === item.index)
|
|
|
+ // value.splice(index, 1)
|
|
|
+ // emit('update:value', [...value])
|
|
|
+ // } else {
|
|
|
+ // emit('update:value', [item.index, ...value])
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // emit('update:value', item.index)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ nextTick(() => {
|
|
|
+ const el = document.getElementById(state.domId)
|
|
|
+ state.sortable = Sortable.create(el, {
|
|
|
+ // disabled: true,
|
|
|
+ animation: 150,
|
|
|
+ sort: true,
|
|
|
+ fallbackTolerance: 3,
|
|
|
+ onUpdate: (evt: any) => {
|
|
|
+ // console.log(evt, 'update')
|
|
|
+ const updatePosition = (list: any) =>
|
|
|
+ list.splice(evt.newIndex, 0, list.splice(evt.oldIndex, 1)[0])
|
|
|
+
|
|
|
+ // const list = deepClone(state.options)
|
|
|
+ // updatePosition(list)
|
|
|
+
|
|
|
+ // state.options = list
|
|
|
+ if (state.list && state.list.length > 0) {
|
|
|
+ updatePosition(state.list)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ state.list = [...state.options]
|
|
|
+ updatePosition(state.list)
|
|
|
+ // console.log(updatePosition(state.options))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return () => (
|
|
|
+ <div class={styles.unitSubject}>
|
|
|
+ <div class={styles.unitSubjectTitle}>
|
|
|
+ 1、选出与方框内音符时值相同的节奏阶段 <span class={styles.unitScore}>(5分)</span>
|
|
|
+ <Tag type="primary">排序题</Tag>
|
|
|
+ </div>
|
|
|
+ <Image
|
|
|
+ class={styles.unitTitleImg}
|
|
|
+ src="https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/dbb27307d428424c8efb9f26032cfa1a_mergeImage.png"
|
|
|
+ />
|
|
|
+
|
|
|
+ <div class={[styles.unitAnswers, 'van-hairline--top']}>
|
|
|
+ <div class={styles.sortReset}>
|
|
|
+ <span class={styles.tips}>请长按拖拽答案进行排序</span>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ round
|
|
|
+ onClick={() => {
|
|
|
+ console.log(11, state.sortable)
|
|
|
+ // state.list = state.list.sort((a: any, b: any) => a.index - b.index)
|
|
|
+ // console.log(c, '222')
|
|
|
+ // state.options = c
|
|
|
+ // console.log(state.options, state.list)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 重置
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ <div id={state.domId}>
|
|
|
+ {state.options.map((item: any) => (
|
|
|
+ <Tag class={[styles.items]}>{item.value + item.index}</Tag>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+})
|