update 优化props 使用propTypes

This commit is contained in:
ahao 2023-09-23 21:45:27 +08:00
parent 978a1a87bf
commit 9abd941eb5
12 changed files with 47 additions and 105 deletions

View File

@ -11,15 +11,11 @@
<script setup lang="ts">
import { propTypes } from "@/utils/propTypes";
const props = defineProps({
showBtn: {
type: Boolean,
default: false
},
formJson: {
type: Object,
default: undefined
}
showBtn: propTypes.bool.def(false),
formJson: propTypes.object.def({})
})
const designerConfig = reactive({
@ -32,12 +28,9 @@ const designerConfig = reactive({
formTemplates: true
})
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const buildRef = ref();
const emits = defineEmits(['reJson', 'saveDesign']);
//json
const getJson = () => {
const formJson = JSON.stringify(buildRef.value.getFormJson())

View File

@ -1,22 +1,15 @@
<!-- 动态表单渲染 -->
<script setup name="Render">
import { propTypes } from "@/utils/propTypes";
const props = defineProps({
formJson: {
type: [String, Object],
default: ""
},
formData: {
type: [String, Object],
default: ""
},
isView: {
type: Boolean,
default: false
}
formJson: propTypes.oneOfType([propTypes.object, propTypes.string]).def(''),
formData: propTypes.oneOfType([propTypes.object, propTypes.string]).def(''),
isView: propTypes.bool.def(false)
})
const vFormRef = ref(null)
const vFormRef = ref()
// -
const getFormData = () => {
return vFormRef.value.getFormData()
@ -24,7 +17,7 @@ const getFormData = () => {
/**
* 设置表单内容
* @param {表单配置} formConf
* @param { * } formConf
* formConfig{ formTemplate表单模板formData表单数据hiddenField需要隐藏的字段字符串集合disabledField需要禁用的自读字符串集合}
*/
const initForm = (formConf) => {

View File

@ -25,16 +25,13 @@
<script setup lang="ts">
import { propTypes } from '@/utils/propTypes';
import { array } from "vue-types";
const props = defineProps({
//
options: {
type: Array as PropType<DictDataOption[]>,
default: null,
},
options: array<DictDataOption>().def([]),
//
value: [Number, String, Array] as PropType<number | string | Array<number | string>>,
value: propTypes.oneOfType([propTypes.string, propTypes.number, array<number | string>()]),
// value
showValue: propTypes.bool.def(true),
});

View File

@ -13,14 +13,8 @@ import { propTypes } from '@/utils/propTypes';
const props = defineProps({
src: propTypes.string.def(''),
width: {
type: [Number, String],
default: ""
},
height: {
type: [Number, String],
default: ""
}
width: propTypes.oneOfType([propTypes.string, propTypes.number]).def(''),
height: propTypes.oneOfType([propTypes.string, propTypes.number]).def('')
});
const realSrc = computed(() => {
@ -33,7 +27,7 @@ const realSrc = computed(() => {
const realSrcList = computed(() => {
if (!props.src) {
return;
return [];
}
let real_src_list = props.src.split(",");
let srcList: string[] = [];

View File

@ -55,10 +55,7 @@ const props = defineProps({
// , ['png', 'jpg', 'jpeg']
fileType: propTypes.array.def(["png", "jpg", "jpeg"]),
//
isShowTip: {
type: Boolean,
default: true
},
isShowTip: propTypes.bool.def(true)
});
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

View File

@ -22,16 +22,14 @@ export default {
<script setup lang="ts">
import { scrollTo } from '@/utils/scroll-to'
import { propTypes } from "@/utils/propTypes";
import { propTypes } from '@/utils/propTypes';
import { array } from 'vue-types';
const props = defineProps({
total: propTypes.number,
page: propTypes.number.def(1),
limit: propTypes.number.def(20),
pageSizes: {
type: Array as PropType<number[]>,
default: () => [10, 20, 30, 50]
},
pageSizes: array<number>().def([10, 20, 30, 50]),
// 5
pagerCount: propTypes.number.def(document.body.clientWidth < 992 ? 5 : 7),
layout: propTypes.string.def('total, sizes, prev, pager, next, jumper'),

View File

@ -19,12 +19,11 @@
<script setup lang="ts">
import { propTypes } from '@/utils/propTypes';
import { array } from "vue-types";
const props = defineProps({
showSearch: propTypes.bool.def(true),
columns: {
type: Array as PropType<FieldOption[]>,
},
columns: array<FieldOption>(),
search: propTypes.bool.def(true),
gutter: propTypes.number.def(10),
})

View File

@ -30,40 +30,23 @@
<script setup lang="ts">
import { propTypes } from "@/utils/propTypes";
const props = defineProps({
/* 配置项 */
objMap: {
type: Object,
default: () => {
return {
value: 'id', // ID
label: 'label', //
children: 'children' //
}
}
},
objMap: propTypes.object.def({
value: 'id', // ID
label: 'label', //
children: 'children' //
}),
/* 自动收起 */
accordion: {
type: Boolean,
default: () => {
return false
}
},
accordion: propTypes.bool.def(false),
/**当前双向数据绑定的值 */
value: {
type: [String, Number],
default: ''
},
value: propTypes.oneOfType([propTypes.string, propTypes.number]),
/**当前的数据 */
options: {
type: Array,
default: () => []
},
options: propTypes.array.def([]),
/**输入框内部的文字 */
placeholder: {
type: String,
default: ''
}
placeholder: propTypes.string.def('')
})

View File

@ -5,14 +5,11 @@
</template>
<script setup lang="ts">
import { propTypes } from '@/utils/propTypes';
const props = defineProps({
src: {
type: String,
default: "/"
},
iframeId: {
type: String
}
src: propTypes.string.def('/'),
iframeId: propTypes.string
});
const height = ref(document.documentElement.clientHeight - 94.5 + "px");
const height = ref(document.documentElement.clientHeight - 94.5 + 'px');
</script>

View File

@ -6,12 +6,10 @@
<script setup lang="ts">
import { isExternal } from '@/utils/validate'
import { propTypes } from "@/utils/propTypes";
const props = defineProps({
to: {
type: [String, Object],
required: true
}
to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired
})
const isExt = computed(() => {
@ -25,7 +23,7 @@ const type = computed(() => {
return 'router-link'
})
function linkProps() {
const linkProps = () => {
if (isExt.value) {
return {
href: props.to,

View File

@ -26,13 +26,11 @@ import variables from '@/assets/styles/variables.module.scss'
import logo from '@/assets/logo/logo.png'
import useSettingsStore from '@/store/modules/settings'
import { ComponentInternalInstance } from "vue";
import { propTypes } from "@/utils/propTypes";
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
defineProps({
collapse: {
type: Boolean,
required: true
}
collapse: propTypes.bool.def(true)
})
const title = ref('RuoYi-Vue-Plus');

View File

@ -35,6 +35,7 @@ import AppLink from './Link.vue'
import { getNormalPath } from '@/utils/ruoyi'
import { RouteOption } from "vue-router";
import { PropType } from "vue";
import { propTypes } from "@/utils/propTypes";
const props = defineProps({
// route object
@ -42,14 +43,8 @@ const props = defineProps({
type: Object as PropType<RouteOption>,
required: true
},
isNest: {
type: Boolean,
default: false
},
basePath: {
type: String,
default: ''
}
isNest: propTypes.bool.def(false),
basePath: propTypes.string.def('')
})
const onlyOneChild = ref<any>({});