mirror of
https://github.com/bufanyun/hotgo.git
synced 2026-02-15 19:04:30 +08:00
发布v2.16.10版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
144
web/src/components/ComplexMemberPicker/index.vue
Normal file
144
web/src/components/ComplexMemberPicker/index.vue
Normal file
@@ -0,0 +1,144 @@
|
||||
<template>
|
||||
<n-input-group>
|
||||
<n-select
|
||||
v-bind="$props"
|
||||
:style="{ width: '68%' }"
|
||||
v-model:value="memberId"
|
||||
:options="memberOption"
|
||||
:render-label="renderLabel"
|
||||
:filter="handleReceiverFilter"
|
||||
@update:value="handleChangeMemberId"
|
||||
clearable
|
||||
filterable
|
||||
/>
|
||||
<n-select
|
||||
:consistent-menu-width="false"
|
||||
:style="{ width: '32%', 'min-width': '90px' }"
|
||||
:options="selectOptions"
|
||||
v-model:value="optVal"
|
||||
@update:value="handleUpdateOptions"
|
||||
/>
|
||||
</n-input-group>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { h, onMounted, ref, watch } from 'vue';
|
||||
import { GetMemberOption } from '@/api/org/user';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { NText, SelectRenderLabel } from 'naive-ui';
|
||||
import { basicProps } from './props';
|
||||
|
||||
const props = defineProps({
|
||||
...basicProps,
|
||||
});
|
||||
const emit = defineEmits(['update:value']);
|
||||
const userStore = useUserStore();
|
||||
const memberId = ref(null);
|
||||
const optVal = ref('-1');
|
||||
const memberOption = ref([]);
|
||||
const selectOptions = [
|
||||
{
|
||||
label: '查全部',
|
||||
value: '-1',
|
||||
},
|
||||
{
|
||||
label: '查本人',
|
||||
value: '1',
|
||||
},
|
||||
{
|
||||
label: '查下级',
|
||||
value: '2',
|
||||
},
|
||||
];
|
||||
|
||||
const renderLabel: SelectRenderLabel = (option: { username: ''; label: '' }) => {
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
},
|
||||
},
|
||||
[
|
||||
h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
padding: '4px 0',
|
||||
display: 'flex',
|
||||
},
|
||||
},
|
||||
[
|
||||
h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
marginRight: '4px',
|
||||
},
|
||||
},
|
||||
[option.username as string]
|
||||
),
|
||||
h(
|
||||
NText,
|
||||
{ depth: 3, tag: 'div' },
|
||||
{
|
||||
default: () => option.label as string,
|
||||
}
|
||||
),
|
||||
]
|
||||
),
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
function handleReceiverFilter(pattern: string, option: object): boolean {
|
||||
const isPatternInLabel = option.label.includes(pattern);
|
||||
const isPatternInUsername = option.username.includes(pattern);
|
||||
const isValueEqual = option.value.toString() === pattern;
|
||||
return isPatternInLabel || isPatternInUsername || isValueEqual;
|
||||
}
|
||||
|
||||
function handleChangeMemberId(v: string) {
|
||||
memberId.value = v;
|
||||
handleUpdateValue();
|
||||
}
|
||||
|
||||
function handleUpdateOptions(value: string) {
|
||||
optVal.value = value;
|
||||
handleUpdateValue();
|
||||
}
|
||||
|
||||
function handleUpdateValue() {
|
||||
if (memberId.value) {
|
||||
emit('update:value', [memberId.value, optVal.value]);
|
||||
} else {
|
||||
emit('update:value', null);
|
||||
}
|
||||
}
|
||||
|
||||
function resetFields() {
|
||||
memberId.value = null;
|
||||
optVal.value = '-1';
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(v) => {
|
||||
if (!v) {
|
||||
resetFields();
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
GetMemberOption().then((res) => {
|
||||
if (res) {
|
||||
memberOption.value = res;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less"></style>
|
||||
13
web/src/components/ComplexMemberPicker/props.ts
Normal file
13
web/src/components/ComplexMemberPicker/props.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { NSelect } from 'naive-ui';
|
||||
|
||||
export const basicProps = {
|
||||
...NSelect.props,
|
||||
defaultValue: {
|
||||
type: [Array],
|
||||
default: null,
|
||||
},
|
||||
value: {
|
||||
type: [Array],
|
||||
default: null,
|
||||
},
|
||||
};
|
||||
@@ -66,6 +66,13 @@
|
||||
v-bind="getComponentProps(schema)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="schema.component === 'ComplexMemberPicker'">
|
||||
<ComplexMemberPicker
|
||||
:class="{ isFull: schema.isFull !== false && getProps.isFull }"
|
||||
v-model:value="formModel[schema.field]"
|
||||
v-bind="getComponentProps(schema)"
|
||||
/>
|
||||
</template>
|
||||
<!--动态渲染表单组件-->
|
||||
<component
|
||||
v-else
|
||||
@@ -147,18 +154,16 @@
|
||||
import { createPlaceholderMessage } from './helper';
|
||||
import { useFormEvents } from './hooks/useFormEvents';
|
||||
import { useFormValues } from './hooks/useFormValues';
|
||||
|
||||
import ComplexMemberPicker from '../../ComplexMemberPicker/index.vue';
|
||||
import { basicProps } from './props';
|
||||
import { DownOutlined, UpOutlined, QuestionCircleOutlined } from '@vicons/antd';
|
||||
|
||||
import type { Ref } from 'vue';
|
||||
import type { GridProps } from 'naive-ui/lib/grid';
|
||||
import type { FormSchema, FormProps, FormActionType } from './types/form';
|
||||
|
||||
import {isArray, isBoolean, isFunction} from '@/utils/is';
|
||||
import { isArray, isBoolean, isFunction } from '@/utils/is';
|
||||
import { deepMerge } from '@/utils';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import {ActionItem} from "@/components/Table";
|
||||
import { ActionItem } from '@/components/Table';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'BasicForm',
|
||||
@@ -237,7 +242,7 @@
|
||||
});
|
||||
|
||||
const getBindValue = computed(
|
||||
() => ({ ...attrs, ...props, ...unref(getProps) } as Recordable)
|
||||
() => ({ ...attrs, ...props, ...unref(getProps) }) as Recordable
|
||||
);
|
||||
|
||||
const getSchema = computed((): FormSchema[] => {
|
||||
|
||||
@@ -25,4 +25,5 @@ export type ComponentType =
|
||||
| 'NIconPicker'
|
||||
| 'NRender'
|
||||
| 'NSlider'
|
||||
| 'NRate';
|
||||
| 'NRate'
|
||||
| 'ComplexMemberPicker';
|
||||
|
||||
Reference in New Issue
Block a user