diff --git a/packages/renderless/src/area/vue.ts b/packages/renderless/src/area/vue.ts index f0b090ccb..a990a79e1 100644 --- a/packages/renderless/src/area/vue.ts +++ b/packages/renderless/src/area/vue.ts @@ -11,14 +11,25 @@ */ import { getRegion, changeOffice, getRep, getOffice, fetchDefaultData, beforeMount } from './index' +import type { + IAreaProps, + IAreaApi, + IAreaState, + ISharedRenderlessParamHooks, + ISharedRenderlessParamUtils +} from '@/types' export const api = ['state', 'getRep', 'getRegion', 'getOffice', 'changeOffice'] -export const renderless = (props, { onBeforeMount, reactive }, { emit, service, refs, nextTick }) => { - const api = {} +export const renderless = ( + props: IAreaProps, + { onBeforeMount, reactive }: ISharedRenderlessParamHooks, + { emit, service, refs, nextTick }: ISharedRenderlessParamUtils +) => { + const api: Partial = {} const { fetchArea } = service || {} - const state = reactive({ + const state = reactive({ jcr: '', region: '', rep: '', @@ -32,14 +43,14 @@ export const renderless = (props, { onBeforeMount, reactive }, { emit, service, Object.assign(api, { state, changeOffice: changeOffice({ emit, state }), - beforeMount: beforeMount({ api, props }), + beforeMount: beforeMount({ api: api as IAreaApi, props }), getRep: getRep({ emit, fetchArea, nextTick, props, refs, state }), getRegion: getRegion({ emit, fetchArea, nextTick, props, refs, state }), getOffice: getOffice({ emit, fetchArea, nextTick, props, refs, state }), fetchDefaultData: fetchDefaultData({ emit, fetchArea, nextTick, props, refs, state }) }) - onBeforeMount(api.beforeMount) + onBeforeMount((api as IAreaApi).beforeMount) - return api + return api as IAreaApi } diff --git a/packages/renderless/types/area.type.ts b/packages/renderless/types/area.type.ts index e69de29bb..cf89d3267 100644 --- a/packages/renderless/types/area.type.ts +++ b/packages/renderless/types/area.type.ts @@ -0,0 +1,41 @@ +import type { ExtractPropTypes } from 'vue' +import type { areaProps } from '@/area/src' +import type { getRegion, changeOffice, getRep, getOffice, fetchDefaultData, beforeMount } from '../src/area' +import type { ISharedRenderlessParamUtils } from '@/types' + +export interface LabeValue { + label: string + value: string +} + +export interface IAreaState { + jcr: string + region: string + rep: string + office: string + jcrData: LabeValue[] + regionData: LabeValue[] + repData: LabeValue[] + officeData: LabeValue[] +} + +export interface IAreaRenderlessParams { + emit: ISharedRenderlessParamUtils['emit'] + fetchArea: (args: { label: string; parent: string }) => Promise + nextTick: ISharedRenderlessParamUtils['nextTick'] + props: IAreaProps + refs: ISharedRenderlessParamUtils['refs'] + state: IAreaState +} + +export type IAreaProps = ExtractPropTypes + +export interface IAreaApi { + state: IAreaState + changeOffice: ReturnType + beforeMount: ReturnType + getRep: ReturnType + getRegion: ReturnType + getOffice: ReturnType + fetchDefaultData: ReturnType +} diff --git a/packages/vue/src/area/src/index.ts b/packages/vue/src/area/src/index.ts new file mode 100644 index 000000000..306ecfb95 --- /dev/null +++ b/packages/vue/src/area/src/index.ts @@ -0,0 +1,47 @@ +import { $prefix, $setup, defineComponent } from '@opentiny/vue-common' +import template from 'virtual-template?pc' + +export const areaProps = { + modelValue: {}, + placeholder: { + type: String, + default: '' + }, + size: String, + disabled: { + type: Boolean, + default: false + }, + props: { + type: Object, + default: () => ({ + label: 'name_cn', + value: 'org_id' + }) + }, + fetchJcr: { + type: Function + }, + fetchRegion: { + type: Function + }, + fetchRep: { + type: Function + }, + fetchOffice: { + type: Function + }, + popperClass: String, + popperAppendToBody: { + type: Boolean, + default: true + } +} + +export default defineComponent({ + name: $prefix + 'Area', + props: areaProps, + setup(props, context) { + return $setup({ props, context, template }) + } +})