diff --git a/src/pages-sub/components/table/Table.vue b/src/pages-sub/components/table/Table.vue index 41e3abe..dbc39c0 100644 --- a/src/pages-sub/components/table/Table.vue +++ b/src/pages-sub/components/table/Table.vue @@ -4,8 +4,7 @@ {{ column.label }} @@ -15,8 +14,7 @@ {{ item[column.prop] }} @@ -55,7 +53,7 @@ const { columns } = useTable() display: flex; align-items: center; justify-content: center; - + padding: 8rpx 0; font-size: 24rpx; color: #333333; box-sizing: border-box; diff --git a/src/pages-sub/components/table/TableCol.vue b/src/pages-sub/components/table/TableCol.vue index 95d2978..9f545d9 100644 --- a/src/pages-sub/components/table/TableCol.vue +++ b/src/pages-sub/components/table/TableCol.vue @@ -13,6 +13,7 @@ const props = defineProps<{ label: string width?: string align?: 'left' | 'center' | 'right' + colClass?: string }>() const { addColumn } = useTableInject() @@ -24,6 +25,7 @@ onMounted(() => { label: props.label, width: props.width, align: props.align, + colClass: props.colClass, slot: slot, }) }) diff --git a/src/pages-sub/components/table/WXXTable.vue b/src/pages-sub/components/table/WXXTable.vue new file mode 100644 index 0000000..6c6caba --- /dev/null +++ b/src/pages-sub/components/table/WXXTable.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/pages-sub/components/table/WXXTableCol.vue b/src/pages-sub/components/table/WXXTableCol.vue new file mode 100644 index 0000000..a7a7ac3 --- /dev/null +++ b/src/pages-sub/components/table/WXXTableCol.vue @@ -0,0 +1,103 @@ + + + + + diff --git a/src/pages-sub/components/table/types.ts b/src/pages-sub/components/table/types.ts new file mode 100644 index 0000000..795d221 --- /dev/null +++ b/src/pages-sub/components/table/types.ts @@ -0,0 +1,21 @@ +import type { CSSProperties, ExtractPropTypes, InjectionKey } from 'vue' + +import type { PropType } from 'vue' + +export const tableProps = { + data: [], +} + +export type TableProps = ExtractPropTypes + +export type TableProvide = { + props: Omit + state: { + scrollLeft: number + } + rowClick: (index: number) => void + getIsLastFixed: (column: { fixed: boolean; prop: string }) => boolean + getFixedStyle: (index: number, style: CSSProperties) => CSSProperties +} + +export const TABLE_KEY: InjectionKey = Symbol('wd-table') diff --git a/src/pages-sub/components/table/useChildren.ts b/src/pages-sub/components/table/useChildren.ts new file mode 100644 index 0000000..98076b4 --- /dev/null +++ b/src/pages-sub/components/table/useChildren.ts @@ -0,0 +1,122 @@ +import { + provide, + reactive, + getCurrentInstance, + type VNode, + type InjectionKey, + type VNodeNormalizedChildren, + type ComponentPublicInstance, + type ComponentInternalInstance, +} from 'vue' + +// 小程序端不支持从vue导出的isVNode方法,参考uni-mp-vue的实现 +function isVNode(value: any): value is VNode { + return value ? value.__v_isVNode === true : false +} + +export function flattenVNodes(children: VNodeNormalizedChildren) { + const result: VNode[] = [] + + const traverse = (children: VNodeNormalizedChildren) => { + if (Array.isArray(children)) { + children.forEach((child) => { + if (isVNode(child)) { + result.push(child) + + if (child.component?.subTree) { + result.push(child.component.subTree) + traverse(child.component.subTree.children) + } + + if (child.children) { + traverse(child.children) + } + } + }) + } + } + + traverse(children) + + return result +} + +const findVNodeIndex = (vnodes: VNode[], vnode: VNode) => { + const index = vnodes.indexOf(vnode) + if (index === -1) { + return vnodes.findIndex( + (item) => + vnode.key !== undefined && + vnode.key !== null && + item.type === vnode.type && + item.key === vnode.key, + ) + } + return index +} + +// sort children instances by vnodes order +export function sortChildren( + parent: ComponentInternalInstance, + publicChildren: ComponentPublicInstance[], + internalChildren: ComponentInternalInstance[], +) { + const vnodes = + parent && parent.subTree && parent.subTree.children + ? flattenVNodes(parent.subTree.children) + : [] + + internalChildren.sort((a, b) => findVNodeIndex(vnodes, a.vnode) - findVNodeIndex(vnodes, b.vnode)) + + const orderedPublicChildren = internalChildren.map((item) => item.proxy!) + + publicChildren.sort((a, b) => { + const indexA = orderedPublicChildren.indexOf(a) + const indexB = orderedPublicChildren.indexOf(b) + return indexA - indexB + }) +} + +export function useChildren< + // eslint-disable-next-line + Child extends ComponentPublicInstance = ComponentPublicInstance<{}, any>, + ProvideValue = never, +>(key: InjectionKey) { + const publicChildren: Child[] = reactive([]) + const internalChildren: ComponentInternalInstance[] = reactive([]) + const parent = getCurrentInstance()! + + const linkChildren = (value?: any) => { + const link = (child: ComponentInternalInstance) => { + if (child.proxy) { + internalChildren.push(child) + publicChildren.push(child.proxy as Child) + sortChildren(parent, publicChildren, internalChildren) + } + } + + const unlink = (child: ComponentInternalInstance) => { + const index = internalChildren.indexOf(child) + publicChildren.splice(index, 1) + internalChildren.splice(index, 1) + } + + provide( + key, + Object.assign( + { + link, + unlink, + children: publicChildren, + internalChildren, + }, + value, + ), + ) + } + + return { + children: publicChildren, + linkChildren, + } +} diff --git a/src/pages-sub/components/table/useParent.ts b/src/pages-sub/components/table/useParent.ts new file mode 100644 index 0000000..cdad90e --- /dev/null +++ b/src/pages-sub/components/table/useParent.ts @@ -0,0 +1,40 @@ +import { + ref, + inject, + computed, + onUnmounted, + type InjectionKey, + getCurrentInstance, + type ComponentPublicInstance, + type ComponentInternalInstance, +} from 'vue' + +type ParentProvide = T & { + link(child: ComponentInternalInstance): void + unlink(child: ComponentInternalInstance): void + children: ComponentPublicInstance[] + internalChildren: ComponentInternalInstance[] +} + +export function useParent(key: InjectionKey>) { + const parent = inject(key, null) + if (parent) { + const instance = getCurrentInstance()! + const { link, unlink, internalChildren } = parent + + link(instance) + onUnmounted(() => unlink(instance)) + + const index = computed(() => internalChildren.indexOf(instance)) + + return { + parent, + index, + } + } + + return { + parent: null, + index: ref(-1), + } +} diff --git a/src/pages-sub/components/table/useTable.ts b/src/pages-sub/components/table/useTable.ts index 8d569a0..c0c801f 100644 --- a/src/pages-sub/components/table/useTable.ts +++ b/src/pages-sub/components/table/useTable.ts @@ -6,6 +6,7 @@ export type Column = { width?: string align?: 'left' | 'center' | 'right' slot?: any + colClass?: string } type TableContext = { diff --git a/src/pages-sub/components/table/utils.ts b/src/pages-sub/components/table/utils.ts new file mode 100644 index 0000000..72cd49f --- /dev/null +++ b/src/pages-sub/components/table/utils.ts @@ -0,0 +1,42 @@ +/** + * 获取目标原始类型 + * @param target 任意类型 + * @returns {string} type 数据类型 + */ +export function getType(target: unknown): string { + // 得到原生类型 + const typeStr = Object.prototype.toString.call(target) + // 拿到类型值 + const match = typeStr.match(/\[object (\w+)\]/) + const type = match && match.length ? match[1].toLowerCase() : '' + // 类型值转小写并返回 + return type +} + +export function isFunction(value: any): value is T { + return getType(value) === 'function' || getType(value) === 'asyncfunction' +} + +export const isDef = (value: T): value is NonNullable => value !== undefined && value !== null +/** + * 生成uuid + * @returns string + */ +export function uuid() { + return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4() +} + +function s4() { + return Math.floor((1 + Math.random()) * 0x10000) + .toString(16) + .substring(1) +} + +/** + * @description 判断target是否对象 + * @param value + * @return {boolean} + */ +export function isObj(value: any): value is object { + return Object.prototype.toString.call(value) === '[object Object]' || typeof value === 'object' +} diff --git a/src/pages-sub/home/city/index.vue b/src/pages-sub/home/city/index.vue index 5e06b53..76142b7 100644 --- a/src/pages-sub/home/city/index.vue +++ b/src/pages-sub/home/city/index.vue @@ -57,8 +57,19 @@ const getUserLocation = () => { type: 'wgs84', success: (res) => { const { latitude, longitude } = res - console.log('当前位置的经度:' + res.longitude) - console.log('当前位置的纬度:' + res.latitude) + + getUserCity({ lat: latitude, lng: longitude }).then((resp) => { + if (resp.code === 200) { + let _locationCode = (resp.result as { locationCode: string }).locationCode + cities.map((item) => { + item.provinces.map((city) => { + if (city.code === _locationCode) { + chooseCity(city) + } + }) + }) + } + }) }, fail: () => { uni.showToast({ @@ -69,9 +80,10 @@ const getUserLocation = () => { }) } -// 在页面加载时调用 -onMounted(() => { - getUserLocation() +onLoad(() => { + if (!userStore.userInfo.estimatedAchievement.provinceCode) { + getUserLocation() + } }) diff --git a/src/pages-sub/home/distinguish/index.vue b/src/pages-sub/home/distinguish/index.vue index 69d35ab..f7bb1bf 100644 --- a/src/pages-sub/home/distinguish/index.vue +++ b/src/pages-sub/home/distinguish/index.vue @@ -45,9 +45,14 @@ - + - 123 + @@ -116,7 +121,12 @@ const getUniversityList = () => { }).then((res) => { if (res.code === 200) { let result = res.result as any[] - tableData.value = result + tableData.value = result.map((item) => { + return { + ...item, + type: item.type === 1 ? '虚假大学' : '真实大学', + } + }) } }) } diff --git a/src/pages-sub/home/inputScore/index.vue b/src/pages-sub/home/inputScore/index.vue index da60ad4..d218217 100644 --- a/src/pages-sub/home/inputScore/index.vue +++ b/src/pages-sub/home/inputScore/index.vue @@ -4,6 +4,7 @@ style: { navigationStyle: 'custom', }, + needLogin: true, }