This commit is contained in:
孟帅
2024-04-22 23:08:40 +08:00
parent 82483bd7b9
commit e144b12580
445 changed files with 17457 additions and 6708 deletions

View File

@@ -1,93 +1,99 @@
<template>
<n-date-picker v-bind="$props" v-model:value="modelValue" :shortcuts="shortcuts" :clearable="true"/>
<n-date-picker
v-bind="$props"
v-model:value="modelValue"
:shortcuts="showShortcuts ? shortcuts : undefined"
:clearable="true"
style="width: 100%"
/>
</template>
<script lang="ts">
import { computed, defineComponent, onMounted, ref } from 'vue';
import {
dateToTimestamp,
formatToDate,
formatToDateTime,
timestampToTime,
defShortcuts,
defRangeShortcuts,
} from '@/utils/dateUtil';
import { basicProps } from './props';
import { computed, defineComponent, onMounted, ref } from 'vue';
import {
dateToTimestamp,
defRangeShortcuts,
defShortcuts,
formatToDate,
formatToDateTime,
timestampToTime,
} from '@/utils/dateUtil';
import { basicProps } from './props';
export default defineComponent({
name: 'BasicUpload',
props: {
...basicProps,
},
emits: ['update:formValue', 'update:startValue', 'update:endValue'],
setup(props, { emit }) {
const shortcuts = ref<any>({});
export default defineComponent({
name: 'DatePicker',
props: {
...basicProps,
},
emits: ['update:formValue', 'update:startValue', 'update:endValue'],
setup(props, { emit }) {
const shortcuts = ref<any>({});
function getTimestamp(value) {
let t = dateToTimestamp(value);
if (t === 0) {
return new Date().getTime();
function getTimestamp(value) {
let t = dateToTimestamp(value);
console.log('getTimestamp t:' + t);
if (t === 0) {
return undefined;
}
return t;
}
return t;
}
function setTimestamp(value) {
if (!isTimeType()) {
return formatToDate(new Date(Number(value)).toDateString());
} else {
return formatToDateTime(timestampToTime(Number(value / 1000)));
}
}
function isRangeType() {
return props.type.indexOf('range') != -1;
}
function isTimeType() {
return props.type.indexOf('time') != -1;
}
const modelValue = computed({
get() {
if (!isRangeType()) {
const value = getTimestamp(props.formValue);
if (props.formValue == ""){
emit('update:formValue', setTimestamp(value));
}
return value;
function setTimestamp(value) {
if (value === undefined) {
return undefined;
}
if (!isTimeType()) {
return formatToDate(new Date(Number(value)).toDateString());
} else {
const value = [getTimestamp(props.startValue), getTimestamp(props.endValue)];
if (props.startValue == "" && props.endValue == ""){
return formatToDateTime(timestampToTime(Number(value / 1000)));
}
}
function isRangeType() {
return props.type.indexOf('range') != -1;
}
function isTimeType() {
return props.type.indexOf('time') != -1;
}
const modelValue = computed({
get() {
if (!isRangeType()) {
return getTimestamp(props.formValue);
} else {
const value = [getTimestamp(props.startValue), getTimestamp(props.endValue)];
if (!value[0] && !value[1]) {
return null;
}
return value;
}
},
set(value) {
if (!isRangeType()) {
emit('update:formValue', setTimestamp(value));
} else {
emit('update:startValue', setTimestamp(value[0]));
emit('update:endValue', setTimestamp(value[1]));
}
return value
}
},
set(value) {
},
});
onMounted(async () => {
if (!isRangeType()) {
emit('update:formValue', setTimestamp(value));
shortcuts.value = defShortcuts();
} else {
emit('update:startValue', setTimestamp(value[0]));
emit('update:endValue', setTimestamp(value[1]));
shortcuts.value = defRangeShortcuts();
}
},
});
});
onMounted(async () => {
if (!isRangeType()) {
shortcuts.value = defShortcuts();
} else {
shortcuts.value = defRangeShortcuts();
}
});
return {
modelValue,
shortcuts,
};
},
});
return {
modelValue,
shortcuts,
showShortcuts: props.showShortcuts,
};
},
});
</script>
<style lang="less"></style>

View File

@@ -15,4 +15,8 @@ export const basicProps = {
type: String as PropType<string> | undefined | Date,
default: () => '',
},
showShortcuts: {
type: Boolean as PropType<boolean>,
default: () => true,
},
};

View File

@@ -126,12 +126,14 @@
const emit = defineEmits(['update:value']);
const fileUploadRef = ref();
const dialogWidth = ref('85%');
const dialog = useDialog();
const showModal = ref(false);
const chooserRef = ref();
const previewRef = ref();
const fileList = ref<string[]>([]);
const dialogWidth = computed(() => {
return adaModalWidth(1080);
});
const getCSSProperties = computed(() => {
return {
@@ -246,7 +248,6 @@
);
onMounted(async () => {
adaModalWidth(dialogWidth, 1080);
loadImage();
});
</script>

View File

@@ -59,6 +59,13 @@
v-bind="getComponentProps(schema)"
/>
</template>
<template v-else-if="schema.component === 'NCascader'">
<n-cascader
:class="{ isFull: schema.isFull !== false && getProps.isFull }"
v-model:value="formModel[schema.field]"
v-bind="getComponentProps(schema)"
/>
</template>
<!--动态渲染表单组件-->
<component
v-else
@@ -127,7 +134,16 @@
</template>
<script lang="ts">
import { defineComponent, reactive, ref, computed, unref, onMounted, watch } from 'vue';
import {
defineComponent,
reactive,
ref,
computed,
unref,
onMounted,
watch,
defineExpose,
} from 'vue';
import { createPlaceholderMessage } from './helper';
import { useFormEvents } from './hooks/useFormEvents';
import { useFormValues } from './hooks/useFormValues';
@@ -139,8 +155,10 @@
import type { GridProps } from 'naive-ui/lib/grid';
import type { FormSchema, FormProps, FormActionType } from './types/form';
import { isArray } 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";
export default defineComponent({
name: 'BasicForm',
@@ -158,6 +176,7 @@
const gridCollapsed = ref(true);
const loadingSub = ref(false);
const isUpdateDefaultRef = ref(false);
const { hasPermission } = usePermission();
const getSubmitBtnOptions = computed(() => {
return Object.assign(
@@ -222,7 +241,12 @@
);
const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
const rawSchemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
const schemas = rawSchemas.filter((schema) => {
return hasPermission(schema.auth as string[]) && isIfShow(schema);
});
for (const schema of schemas) {
const { defaultValue } = schema;
// handle date type
@@ -240,6 +264,20 @@
formModel,
});
function isIfShow(action: ActionItem): boolean {
const ifShow = action.ifShow;
let isIfShow = true;
if (isBoolean(ifShow)) {
isIfShow = ifShow;
}
if (isFunction(ifShow)) {
isIfShow = ifShow(action);
}
return isIfShow;
}
const { handleSubmit, validate, resetFields, getFieldsValue, clearValidate, setFieldsValue } =
useFormEvents({
emit,
@@ -314,6 +352,7 @@
isInline,
getComponentProps,
unfoldToggle,
setFieldsValue,
};
},
});

View File

@@ -2,6 +2,8 @@ import { ComponentType } from './index';
import type { CSSProperties } from 'vue';
import type { GridProps, GridItemProps } from 'naive-ui/lib/grid';
import type { ButtonProps } from 'naive-ui/lib/button';
import {PermissionsEnum} from "@/enums/permissionsEnum";
import { ActionItem } from '@/components/Table';
export interface FormSchema {
field: string;
@@ -16,6 +18,8 @@ export interface FormSchema {
giProps?: GridItemProps;
isFull?: boolean;
suffix?: string;
auth?: PermissionsEnum | PermissionsEnum[] | string | string[];
ifShow?: boolean | ((action: ActionItem) => boolean);
}
export interface FormProps {

View File

@@ -7,12 +7,7 @@
<template v-else>
<AntdSelector v-model:value="formValue" />
</template>
<n-input
v-bind="$props"
:value="formValue"
:style="{ width: '70%' }"
placeholder="请选择图标"
/>
<n-input v-bind="$props" :value="formValue" placeholder="请选择图标" />
</n-input-group>
</div>
</template>

View File

@@ -94,6 +94,7 @@
import { useLockscreenStore } from '@/store/modules/lockscreen';
import { useUserStore } from '@/store/modules/user';
import { aesEcb } from '@/utils/encrypt';
import { TABS_ROUTES } from '@/store/mutation-types';
export default defineComponent({
name: 'Lockscreen',
@@ -149,6 +150,7 @@
if (code === ResultEnum.SUCCESS) {
onLockLogin(false);
useLockscreen.setLock(false);
window.location.reload();
} else {
state.errorMsg = message;
state.isLoginError = true;
@@ -160,11 +162,18 @@
const goLogin = () => {
onLockLogin(false);
useLockscreen.setLock(false);
router.replace({
path: '/login',
query: {
redirect: route.fullPath,
},
userStore.logout().then(() => {
// 移除标签页
localStorage.removeItem(TABS_ROUTES);
router
.replace({
name: 'Login',
query: {
redirect: route.fullPath,
},
})
.finally(() => location.reload());
});
};