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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,12 +6,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { isExternal } from '@/utils/validate' import { isExternal } from '@/utils/validate'
import { propTypes } from "@/utils/propTypes";
const props = defineProps({ const props = defineProps({
to: { to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired
type: [String, Object],
required: true
}
}) })
const isExt = computed(() => { const isExt = computed(() => {
@ -25,7 +23,7 @@ const type = computed(() => {
return 'router-link' return 'router-link'
}) })
function linkProps() { const linkProps = () => {
if (isExt.value) { if (isExt.value) {
return { return {
href: props.to, 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 logo from '@/assets/logo/logo.png'
import useSettingsStore from '@/store/modules/settings' import useSettingsStore from '@/store/modules/settings'
import { ComponentInternalInstance } from "vue"; import { ComponentInternalInstance } from "vue";
import { propTypes } from "@/utils/propTypes";
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
defineProps({ defineProps({
collapse: { collapse: propTypes.bool.def(true)
type: Boolean,
required: true
}
}) })
const title = ref('RuoYi-Vue-Plus'); const title = ref('RuoYi-Vue-Plus');

View File

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