Commit 3c8fe1f3 authored by hucy's avatar hucy

feat:新增判断类型获取类型方法

parent 4b56b9ee
## -alpha
- 新增判断类型获取类型方法
## 2023-01-18 ## 2023-01-18
- 提示框样式修改 - 提示框样式修改
......
/** /**
* Define the common constant
* 定义公共常数 * 定义公共常数
*/ */
......
interface DialogLayoutProps { interface DialogLayoutProps {
title?: any;
width?: number; width?: number;
maxWidth?: number;
minWidth?: number;
height?: number; height?: number;
[proppName: string]: any; maxHeight?: number;
minHeight?: number;
} }
export type { DialogLayoutProps }; export type { DialogLayoutProps };
import { isEmpty } from './isEmpty';
/** /**
* 删除对象中为空的属性值 返回一个新对象 * 删除对象中为空的属性值 返回一个新对象
* @param data - 原始对象 * @param data - 原始对象
...@@ -5,13 +7,7 @@ ...@@ -5,13 +7,7 @@
export const delEmptyObjkey = function (data: any) { export const delEmptyObjkey = function (data: any) {
const obj = {} as any; const obj = {} as any;
for (const key in data) { for (const key in data) {
if ( if (!isEmpty(data[key])) {
data[key] !== null &&
data[key] !== undefined &&
data[key] !== '' &&
JSON.stringify(data[key]) !== '[]' &&
JSON.stringify(data[key]) !== '{}'
) {
obj[key] = data[key]; obj[key] = data[key];
} }
} }
......
export const getType = function (value: any): string {
const typeofs = Object.prototype.toString.call(value);
switch (typeofs) {
case '[object Number]':
return 'Number';
case '[object String]':
return 'String';
case '[object Boolean]':
return 'Boolean';
case '[object Null]':
return 'Null';
case '[object Undefined]':
return 'Undefined';
case '[object Array]':
return 'Array';
case '[object Object]':
return 'Object';
default:
return typeofs;
}
};
...@@ -8,6 +8,8 @@ export * from './json-str'; ...@@ -8,6 +8,8 @@ export * from './json-str';
export * from './isEmpty'; export * from './isEmpty';
export * from './maths'; export * from './maths';
export * from './myCloneDeep'; export * from './myCloneDeep';
export * from './get-type';
export * from './is';
export { export {
cloneDeep, cloneDeep,
orderBy, orderBy,
......
import { getType } from './get-type';
const typeCheck = function (type: string, val: any): boolean {
if (getType(val) === type) {
return true;
} else {
return false;
}
};
type TypeChecking = {
number: (val: any) => boolean;
string: (val: any) => boolean;
array: (val: any) => boolean;
object: (val: any) => boolean;
};
export const is: TypeChecking = {
number: (val: any) => {
return typeCheck('Number', val);
},
string: (val: any) => {
return typeCheck('String', val);
},
array: (val: any) => {
return typeCheck('Array', val);
},
object: (val: any) => {
return typeCheck('Object', val);
},
};
...@@ -171,7 +171,7 @@ function updateProxy() { ...@@ -171,7 +171,7 @@ function updateProxy() {
} }
function onClickDate() { function onClickDate() {
console.log('点击确定', dateProxyDate.value); // console.log('点击确定', dateProxyDate.value);
// 多选 // 多选
if (props.config?.multiple) { if (props.config?.multiple) {
if (isEmpty(dateProxyDate.value)) { if (isEmpty(dateProxyDate.value)) {
......
...@@ -378,9 +378,6 @@ function reset() { ...@@ -378,9 +378,6 @@ function reset() {
margin-bottom: 2px; margin-bottom: 2px;
display: inline-block; display: inline-block;
} }
.form-label-padding-bottom {
padding-bottom: 20px;
}
// :deep(.my-select // :deep(.my-select
// > :nth-child(1) // > :nth-child(1)
......
...@@ -60,39 +60,72 @@ function onSave() { ...@@ -60,39 +60,72 @@ function onSave() {
} }
</script> </script>
<template> <template>
<q-card class="my-card" :style="myCardStyle"> <q-card class="box" :style="myCardStyle">
<div class="card-content"> <div class="main" :style="myCardStyle">
<div class="title">{{ title }}</div> <div class="card-content">
<div class="content"> <div class="title"></div>
<q-scroll-area <div class="content">
style="height: 100%; max-width: 100%" <q-scroll-area
:thumb-style="thumbStyle" style="height: 100%; max-width: 100%"
:bar-style="barStyle" :thumb-style="thumbStyle"
> :bar-style="barStyle"
<slot></slot> >
</q-scroll-area> <slot></slot>
</div> </q-scroll-area>
<div class="bottom-action"> </div>
<q-btn flat style="color: #64b3f4" label="取消" @click="onCancel" /> <div class="bottom-action">
<q-btn <q-btn flat style="color: #64b3f4" label="取消" @click="onCancel" />
unelevated <q-btn
style="background: #64b3f4; color: white" unelevated
label="确定" style="background: #64b3f4; color: white"
@click="onSave()" label="确定"
/> @click="onSave()"
/>
</div>
</div> </div>
</div> </div>
<div class="title-mask">
<span>{{ title }}</span>
</div>
</q-card> </q-card>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.my-card { .box {
position: relative;
}
.title-mask {
box-sizing: border-box;
position: absolute;
top: 29.5px;
height: 30.5px;
border-radius: 0 !important;
border-top-right-radius: 15px !important;
border-bottom-right-radius: 15px !important;
background-color: #64b3f4;
padding-left: 20px;
display: flex;
align-items: center;
box-shadow: rgba(0, 0, 0, 0.07) 0px 1px 1px, rgba(0, 0, 0, 0.07) 0px 2px 2px,
rgba(0, 0, 0, 0.07) 0px 4px 4px, rgba(0, 0, 0, 0.07) 0px 8px 8px,
rgba(0, 0, 0, 0.07) 0px 16px 16px;
> span {
color: white;
font-size: 15px;
font-weight: bold;
padding-left: 8px;
padding-right: 17px;
}
}
.main {
position: relative;
padding: 20px; padding: 20px;
background-image: linear-gradient(60deg, #c2e59c 0%, #64b3f4 100%); background-image: linear-gradient(60deg, #c2e59c 0%, #64b3f4 100%);
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;
} }
.card-content { .card-content {
width: 100%; width: 100%;
background-color: #fff; background-color: #fff;
...@@ -103,13 +136,12 @@ function onSave() { ...@@ -103,13 +136,12 @@ function onSave() {
overflow: hidden; overflow: hidden;
.title { .title {
box-sizing: border-box;
height: 40px; height: 40px;
padding: 8px;
font-size: 16px;
font-weight: bolder; font-weight: bolder;
color: #c2e59c;
display: flex; display: flex;
align-items: center; align-items: flex-end;
// border: 1px solid red;
} }
.content { .content {
flex: 1; flex: 1;
......
...@@ -45,6 +45,9 @@ a:hover { ...@@ -45,6 +45,9 @@ a:hover {
transform: scale(1.5) translateY(1px); transform: scale(1.5) translateY(1px);
// transform: translateY(5px); // transform: translateY(5px);
} }
.form-label-padding-bottom {
padding-bottom: 20px;
}
// tooltip样式 // tooltip样式
.com-tooltip-sty { .com-tooltip-sty {
......
...@@ -60,50 +60,21 @@ export const form_config = [ ...@@ -60,50 +60,21 @@ export const form_config = [
label: '开始日期~结束日期', label: '开始日期~结束日期',
col: 'col-4', col: 'col-4',
type: 'dateRange', type: 'dateRange',
required: true,
bind: { bind: {
filled: true, filled: true,
clearable: true, clearable: true,
dateMask: 'YYYY-MM-DD', dateMask: 'YYYY-MM-DD',
rules: [(val: any) => !isEmpty(val) || '必填'],
}, },
}, },
{ {
fild: 'platform', solt: 'days',
label: '平台',
col: 'col-4', col: 'col-4',
type: 'select', },
bind: { {
filled: true, solt: 'social',
multiple: true, col: 'col-12',
clearable: true,
emitValue: true,
mapOptions: true,
options: [
{
label: '微信',
value: 'WeChat',
},
{
label: '微博',
value: 'Microblog',
},
{
label: '哔哩哔哩',
value: 'bilibili',
},
{
label: 'Twitter',
value: 'Twitter',
},
{
label: 'Facebook',
value: 'Facebook',
},
{
label: 'AAA',
value: 'aaa',
},
],
},
}, },
{ {
fild: 'remark', fild: 'remark',
......
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'; import { ref, reactive, onMounted, computed } from 'vue';
import { date } from 'quasar';
import { useMessage } from 'src/common/hooks'; import { useMessage } from 'src/common/hooks';
import Com from 'src/components'; import Com from 'src/components';
import { isEmpty } from 'src/common/utils'; import { isEmpty, is } from 'src/common/utils';
import { form_config } from '../config'; import { form_config } from '../config';
import type { DialogLayoutProps } from 'src/common/types'; import type { DialogLayoutProps } from 'src/common/types';
...@@ -21,7 +22,9 @@ const show = ref(false); ...@@ -21,7 +22,9 @@ const show = ref(false);
const state = reactive({ const state = reactive({
readonly: false, readonly: false,
formConfig: [] as any[], formConfig: [] as any[],
formData: {} as any, formData: {
social: [],
} as any,
}); });
const pagestate = reactive<DialogLayoutProps>({ const pagestate = reactive<DialogLayoutProps>({
...@@ -39,12 +42,62 @@ const sexOpt = reactive([ ...@@ -39,12 +42,62 @@ const sexOpt = reactive([
}, },
]); ]);
const socialOpt = reactive([
{
value: 'instagram',
label: 'Instagram',
icon: 'bi-instagram',
},
{
value: 'weibo',
label: '微博',
icon: 'bi-sina-weibo',
},
{
value: 'wechat',
label: '微信',
icon: 'bi-wechat',
},
{
value: 'qq',
label: 'QQ',
icon: 'bi-tencent-qq',
},
{
value: 'twitter',
label: 'Twitter',
icon: 'bi-twitter',
},
]);
const days = computed(() => {
const DATE = state.formData.dateRange;
if (isEmpty(DATE)) {
return '';
} else {
let re;
if (is.object(DATE)) {
const date1 = new Date(DATE.from);
const date2 = new Date(DATE.to);
const unit = 'days';
const diff = date.getDateDiff(date2, date1, unit);
re = diff + 1;
} else {
re = 1;
}
return re;
}
});
onMounted(() => { onMounted(() => {
initFormConfig(); initFormConfig();
}); });
function initDialog() { function initDialog() {
state.formData = {}; state.formData = {
social: [],
};
} }
function initFormConfig() { function initFormConfig() {
...@@ -66,6 +119,7 @@ function onSave() { ...@@ -66,6 +119,7 @@ function onSave() {
if (!suc) return; if (!suc) return;
if (isEmpty(formData.sex)) return warn('性别必填'); if (isEmpty(formData.sex)) return warn('性别必填');
if (formData.social.length < 1) return warn('至少选择一个社交平台');
console.log('formData >>>>', formData); console.log('formData >>>>', formData);
closeDialog(); closeDialog();
...@@ -100,6 +154,38 @@ function onCancel() { ...@@ -100,6 +154,38 @@ function onCancel() {
</div> </div>
</div> </div>
</template> </template>
<template #days>
<div class="item-content">
<div class="label-title text-required">天数</div>
<div class="label-content q-pl-sm">{{ days }}</div>
</div>
</template>
<template #social>
<div class="item-content form-label-padding-bottom">
<div class="label-title text-required">社交</div>
<div class="label-content">
<q-option-group
v-model="state.formData.social"
type="checkbox"
:options="socialOpt"
inline
:disable="state.readonly"
>
<template v-slot:label="opt">
<div class="row items-center">
<q-icon
:name="opt.icon"
size="1.5em"
class="q-mr-sm"
color="grey-8"
/>
<span>{{ opt.label }}</span>
</div>
</template>
</q-option-group>
</div>
</div>
</template>
</Com.MyForm> </Com.MyForm>
</Com.DialogLayout> </Com.DialogLayout>
</q-dialog> </q-dialog>
...@@ -107,7 +193,6 @@ function onCancel() { ...@@ -107,7 +193,6 @@ function onCancel() {
<style lang="scss" scoped> <style lang="scss" scoped>
.item-content { .item-content {
height: 40px;
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
...@@ -122,6 +207,8 @@ function onCancel() { ...@@ -122,6 +207,8 @@ function onCancel() {
display: inline-block; display: inline-block;
} }
.label-content { .label-content {
height: 40px;
min-height: 40px;
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment