diff --git a/server/src/modules/survey/utils/index.ts b/server/src/modules/survey/utils/index.ts index 85b39453..dee07eee 100644 --- a/server/src/modules/survey/utils/index.ts +++ b/server/src/modules/survey/utils/index.ts @@ -184,13 +184,15 @@ export function handleAggretionData({ dataMap, item }) { type: dataMap[item.field].type, data: { ...item.data, - aggregation: aggregation.map((item) => { - return { - id: item.id, - text: item.text, - count: aggregationMap[item.id]?.count || 0, - }; - }), + aggregation: aggregation + .map((item) => { + return { + id: item.id, + text: item.text, + count: aggregationMap[item.id]?.count || 0, + }; + }) + .filter((v) => v.count > 0), }, }; } else { diff --git a/web/src/management/pages/edit/components/Picker/index.vue b/web/src/management/pages/edit/components/Picker/index.vue new file mode 100644 index 00000000..2c69dab2 --- /dev/null +++ b/web/src/management/pages/edit/components/Picker/index.vue @@ -0,0 +1,468 @@ + + + + \ No newline at end of file diff --git a/web/src/management/pages/edit/components/Picker/pickerHeader.vue b/web/src/management/pages/edit/components/Picker/pickerHeader.vue new file mode 100644 index 00000000..ad4ca08e --- /dev/null +++ b/web/src/management/pages/edit/components/Picker/pickerHeader.vue @@ -0,0 +1,83 @@ + + + + + \ No newline at end of file diff --git a/web/src/management/pages/edit/components/Picker/pickerList.vue b/web/src/management/pages/edit/components/Picker/pickerList.vue new file mode 100644 index 00000000..ae7e7e0a --- /dev/null +++ b/web/src/management/pages/edit/components/Picker/pickerList.vue @@ -0,0 +1,251 @@ + + + + + \ No newline at end of file diff --git a/web/src/management/pages/edit/components/Picker/utils.ts b/web/src/management/pages/edit/components/Picker/utils.ts new file mode 100644 index 00000000..c6bad545 --- /dev/null +++ b/web/src/management/pages/edit/components/Picker/utils.ts @@ -0,0 +1,16 @@ +export const DEFTAULT_ITEM_HEIGHT = 44 + +// 兼容pc 移动端 +export const HAS_TOUCH = 'ontouchstart' in window +export const START_EVENT = HAS_TOUCH ? 'touchstart' : 'mousedown' +export const MOVE_EVENT = HAS_TOUCH ? 'touchmove' : 'mousemove' +export const END_EVENT = HAS_TOUCH ? 'touchend' : 'mouseup' + +export const getClient = (e:any) => { + const clientX = HAS_TOUCH ? e.changedTouches[0].clientX : e.clientX + const clientY = HAS_TOUCH ? e.changedTouches[0].clientY : e.clientY + return { + x: clientX, + y: clientY + } +} diff --git a/web/src/materials/questions/widgets/MultilevelModule/BaseMultilevel/index.vue b/web/src/materials/questions/widgets/MultilevelModule/BaseMultilevel/index.vue index 9858305f..7fbfdd3f 100644 --- a/web/src/materials/questions/widgets/MultilevelModule/BaseMultilevel/index.vue +++ b/web/src/materials/questions/widgets/MultilevelModule/BaseMultilevel/index.vue @@ -23,7 +23,8 @@ - +
@@ -50,7 +51,7 @@ - - \ No newline at end of file diff --git a/web/src/materials/questions/widgets/MultilevelModule/Picker/list.ts b/web/src/materials/questions/widgets/MultilevelModule/Picker/list.ts deleted file mode 100644 index 4a22b3b6..00000000 --- a/web/src/materials/questions/widgets/MultilevelModule/Picker/list.ts +++ /dev/null @@ -1,128 +0,0 @@ -import { ref, computed } from 'vue' -import type { Ref } from 'vue' - -interface IList { - box: Ref, - list: Ref>, - getOffsetY: any, - getStyle: any, - handleMove: (e: TouchEvent) => void, - handleStart: (e: TouchEvent) => void, - handleEnd: (e: TouchEvent) => void, - goItem: (idx: number) => void, - resetData: () => void, - index: Ref -} - -const useList = (props: any): IList => { - const colors = ['gray', '#ccc', '#ddd', '#eee'] - const scales = [.96, .9, .88, .84] - let startY: number, activeIndex = 0 - const box = ref() - const offY = ref() - const index = ref(0) - const list = ref(props.list) - - const getStyle = (idx: number) => { - let color = '#000', scale = 1 - const len = colors.length - 1 - if (idx > activeIndex) { - const _idx = idx - activeIndex > len ? len : idx - activeIndex - 1 - color = colors[_idx] - scale = scales[_idx] - } else if (idx < activeIndex) { - const _idx = activeIndex - idx > len ? len : activeIndex - idx - 1 - color = colors[_idx] - scale = scales[_idx] - } - return { color, transform: `scale(${scale})` } - } - - // 节流 - const throttle = function (callback: any, delay = 20) { - let timer: any = null - return function (args: any) { - if (timer) { - return - } - timer = setTimeout(() => { - callback(args) - timer = null - }, delay) - } - } - - // 移动的实现 - const move = throttle((e: any) => { - offY.value = e.touches[0].clientY - startY - if (offY.value > 40) { - offY.value = 40 - } else if (offY.value < -box.value.offsetHeight - 40) { - offY.value = -box.value.offsetHeight - 40 - } - // 计算当前位置的就近下标 - index.value = Math.abs(Math.ceil(offY.value / 40)) - // 判断顶部和底部的一个界限,然后做一个位置的重置 - if (index.value <= 0 || offY.value > 0) { - index.value = 0 - } else if (index.value > list.value.length - 1 || offY.value < -box.value.offsetHeight - 18) { - index.value = list.value.length - 1 - } - activeIndex = index.value - }) - - const goItem = (idx: number) => { - index.value = idx; - activeIndex = idx; - } - - const resetData = () => { - startY = 0; - activeIndex = 0 - index.value = 0 - box.value = null; - offY.value = null; - } - - const handleStart = (e: TouchEvent) => { - const transform = box.value.style.transform - transform.match(/,(.*)px/) - startY = e.touches[0].clientY - Number(RegExp.$1) - } - - const handleMove = (e: TouchEvent) => move(e) - - const handleEnd = () => { - // 重置当前位置,加setTimeout避免出现Bug - setTimeout(() => { - offY.value = -index.value * 40 - 18 - }, 100) - } - - const getOffsetY = computed(() => { - if (typeof offY.value === 'number') { - return { - transform: `translate(-50%, ${offY.value}px)` - } - } else { - return { - transform: 'translate(-50%, -18px)' - } - } - }) - - return { - box, - list, - getOffsetY, - getStyle, - handleMove, - handleStart, - handleEnd, - goItem, - resetData, - index - } -} - -export default useList \ No newline at end of file diff --git a/web/src/render/main.js b/web/src/render/main.js index e097d4ca..ca68f229 100644 --- a/web/src/render/main.js +++ b/web/src/render/main.js @@ -3,7 +3,6 @@ import App from './App.vue' import EventBus from './utils/eventbus' import router from './router' import { createPinia } from 'pinia' -import 'default-passive-events' const app = createApp(App) const pinia = createPinia()