Wiidede's blog Wiidede's blog
  • 前端
  • Python
  • 算法
  • 生活
  • 其他
  • 分类
  • 标签
  • 归档
  • 关于我
  • 赞赏
  • 我的小站 (opens new window)
GitHub (opens new window)

Wiidede

小的的写前端
  • 前端
  • Python
  • 算法
  • 生活
  • 其他
  • 分类
  • 标签
  • 归档
  • 关于我
  • 赞赏
  • 我的小站 (opens new window)
GitHub (opens new window)
  • 整理一些css样式
  • vue隔代组件层层动态插槽并且附带数据
  • vue判断字符串是否溢出来显示弹窗、解决el-table tooltip 内过多导致无法显示,内容闪烁
  • 整理一些js写法
  • ElementUI timePicker 增加此刻按钮 引发的dom操作的学习
  • 毕业设计(水表识别)前端知识整理
  • html小知识
  • axios请求api然后下载文件
  • vue3+ts根据高度改变元素的透明度
  • vue3 + ElementPlus 换肤方案(Css变量)
  • Moment的一些使用方法
  • echarts基础vue组件
  • element UI el-date-picker 年月日切换组件
  • 可以不选择的el-radio单选框
  • vue的小技巧总结
  • 全局动态权限判断(Vue指令)
  • vue-anchor 探索
  • Deep Dive with Evan You 笔记
  • 前端基础知识查漏补缺
  • WebPack 知识总结
  • 我写的一些可以日后参考的代码
  • 接口变化后,封装接口函数,改变返回内容
  • 项目组件整理
  • 前端框架设计想发
  • 全局进度条
  • 带有token的图片vue组件:authImg,使用axios下载图片
  • 前端npm包推荐
  • 给ElInputNumber添加prefix
  • ElPagination添加页数总数
  • el-tab做成chrome类似的tab样式
  • vue-grid-layout-组件配置
  • 项目数据字典封装
  • 图表组件响应式探索
  • ElementPlus表格table列自动合并composition
  • 简单的curd组件封装
  • ElementPlus表格自定义合计列composition
  • 一些处理表格数据composition api
  • div内容溢出后,内容向左悬浮,vue组件封装
  • 文本数字溢出后,按比例缩小,vue组件封装
  • 表格使用async-validator检验composition
  • ElementPlus Form一些简单的组件整合
    • 将datePicker,一个时间点,在年/月/日的开始时间、结束时间,分别绑定在两个属性上
    • 将datePicker(range类型)分别绑定在两个属性上,而不是绑定在一个值(数组)上
    • 把 'a,b,c' 这种形式的,绑定到多选组件上
    • 在view模式下使用el-image来展示图片的上传
  • arco-design快速使用tailwind的颜色、unocss动态颜色
  • 前端
wiidede
2023-01-16

ElementPlus Form一些简单的组件整合

# ElementPlus Form一些简单的组件整合

# 将datePicker,一个时间点,在年/月/日的开始时间、结束时间,分别绑定在两个属性上

用法:

<WddDatePickerRange
  v-model:start="searchModel.startTime"
  v-model:end="searchModel.endTime"
  clearable
  value-format="YYYY-MM-DD HH:mm:ss"
/>
1
2
3
4
5
6

组件代码:

<template>
  <el-date-picker
    v-model="DateModel"
    :value-format="valueFormat"
    :type="type"
  />
</template>

<script lang="ts" setup>
import dayjs from 'dayjs';

type DateValue = string | Date | number;

const props = defineProps<{
  start?: DateValue
  end?: DateValue
  valueFormat?: string
  type?: 'year' | 'month' | 'date' | 'week'
}>();

type IEmit = {
  (event: 'update:start', value: typeof props.start): void;
  (event: 'update:end', value: typeof props.end): void;
}
const emit = defineEmits<IEmit>();

const DateModel = computed({
  get: () => props.start,
  set: (value) => {
    if (value ?? dayjs(value).isValid()) {
      const time = dayjs(value);
      const start = time.startOf(props.type || 'date');
      const end = time.endOf(props.type || 'date');
      emit('update:start', props.valueFormat === undefined ? start.toDate() : start.format(props.valueFormat));
      emit('update:end', props.valueFormat === undefined ? end.toDate() : end.format(props.valueFormat));
    } else {
      emit('update:start', value);
      emit('update:end', value);
    }
  },
});
</script>

<style lang="scss" scoped>

</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

# 将datePicker(range类型)分别绑定在两个属性上,而不是绑定在一个值(数组)上

用法:

<WddDateRangePicker
  v-model:start="form.beginDate"
  v-model:end="form.endDate"
  type="daterange"
  size="large"
  value-format="YYYY-MM-DD HH:mm:ss"
  range-separator="~"
  start-placeholder="开始日期"
  end-placeholder="结束日期"
  clearable
/>
1
2
3
4
5
6
7
8
9
10
11

组件代码:

<template>
  <el-date-picker
    v-model="DateModel"
  />
</template>

<script lang="ts" setup>
type DateValue = string | Date | number;

const props = defineProps<{
  start?: DateValue
  end?: DateValue
}>();

type IEmit = {
  (event: 'update:start', value: typeof props.start): void;
  (event: 'update:end', value: typeof props.end): void;
}
const emit = defineEmits<IEmit>();

const DateModel = computed({
  get: () => [props.start, props.end],
  set: (value) => {
    emit('update:start', value?.[0]);
    emit('update:end', value?.[1]);
  },
});
</script>

<style lang="scss" scoped>

</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 把 'a,b,c' 这种形式的,绑定到多选组件上

用法:

<WddSelectMultiString v-if="![null, undefined].includes(row?.zone)" v-model="row.zone" placeholder="请选择" clearable collapse-tags>
  <el-option
    v-for="(value, key) in zoneMap"
    :key="key"
    :label="value"
    :value="value"
  />
</WddSelectMultiString>
1
2
3
4
5
6
7
8

组件代码:

<template>
  <el-select v-model="model" multiple>
    <slot />
  </el-select>
</template>

<script lang="ts" setup>
const props = defineProps<{
  modelValue: string
}>();

type IEmit = {
  (event: 'update:modelValue', value: typeof props.modelValue): void;
}
const emit = defineEmits<IEmit>();

const model = computed({
  get: () => (props.modelValue === '' ? [] : props.modelValue.split(',')),
  set: (value) => {
    if (Array.isArray(value)) {
      emit('update:modelValue', value.join(','));
    }
  },
});
</script>

<style lang="scss" scoped>

</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 在view模式下使用el-image来展示图片的上传

用法:


1

组件代码:

<template>
  <el-upload
    class="dr-upload" v-model:file-list="fileListModel" multiple drag action="#"
    :auto-upload="false" :limit="10"
    v-bind="$attrs"
  >
    <i class="upload-icon">
      <div class="i-t-file-upload" />
    </i>
    <div class="el-upload__text">
      <span>点击或将文件拖拽到这里上传</span>
      <div class="tip">支持扩展名:.jpg, .png</div>
    </div>
    <template #tip>
      <div class="dr-upload-file-list">
        <div v-for="(file, index) in fileListModel" :key="index">
          <el-image
            v-if="pictureUrls[file.url]"
            style="height: 100px"
            :src="pictureUrls[file.url]"
            hide-on-click-modal
            :preview-src-list="fileListModel.map((item: any) => pictureUrls[item.url])"
            :initial-index="index"
            fit="cover"
          />
          <el-link v-else w-fit :underline="false" @click="onPreview(file)">
            <el-icon mr1><Link /></el-icon>{{ file.name }}
          </el-link>
        </div>
      </div>
    </template>
  </el-upload>
</template>

<script lang="ts" setup>
import type { UploadProps } from 'element-plus/es';

const props = defineProps<{
  fileList?: any
}>();

type IEmit = {
  (event: 'update:fileList', value: typeof props.fileList): void;
}
const emit = defineEmits<IEmit>();

const fileListModel = computed({
  get: () => props.fileList,
  set: (value) => emit('update:fileList', value),
});

const onPreview: UploadProps['onPreview'] = (uploadFile) => {
  if (uploadFile.url) {
    download('channeldredging', uploadFile.url, uploadFile.name);
  }
};

const pictureUrls = ref<Record<string, string>>({});

watch(() => props.fileList, (val) => {
  if (!val) {
    fileListModel.value = [];
    return;
  }

  val.forEach(async (file: any) => {
    pictureUrls.value = {};
    if (!file.url) { return; }
    const suffix = file.url?.split('.').pop();
    const isPicture = ['jpg', 'png'].includes(suffix as string);
    if (isPicture) {
      pictureUrls.value[file.url] = file.url; // 这里本意是想对图片url进行处理的
    }
  });
}, {
  immediate: true,
});
</script>

<style lang="scss" scoped>
.dr-upload-file-list {
  display: none;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#Vue组件#Vue#Element Plus
上次更新: 2023/06/01, 12:40:50

← 表格使用async-validator检验composition arco-design快速使用tailwind的颜色、unocss动态颜色→

Theme by Vdoing | Copyright © 2021-2023 Wiidede | Website use MIT License | Article content & logo use CC-BY-SA-4.0 License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式