1.2.1 • Published 2 years ago

vue2_ts_components v1.2.1

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

使用说明

使用背景

vue2_ts_component 基于vue2.x 完成搭建。

使用建议为:项目为vue2版本 ,支持国际化

组件主要为系统管理产品提供较快封装组件,通过配置项免去手写页面。

涉及的自定义配置组件,内部均有默认配置,你可以先观察默认情况是否满足你的预期,再进行修改,这将减少你不必要的配置

开始

安装

npm i vue2_ts_components

配置使用

import 'vue2_ts_components/dist/app.css';
import vue2TSComponent from 'vue2_ts_components';

/**
   如果你需要使用ts约束分页、各类配置
   你可以引入以下ts
**/
import 'vue2_ts_components/src/ts/comm.ts';


Vue.use(vue2TSComponent);



const data = new Vue({
  render: h => h(App),
}).$mount('#app')

国际化问题

项目封装的组件已经完成了国际化中文 and 英文展示,通过localStroge.getItem('lang')来区分当前环境中英文

其中CN 代表中文EN 代表 英文

有时候我们环境localStroge.getItem('lang') 已经用于其它变量,为此,你可以在Vue.use(Vue2_ts_components,{lang: 'currentLang'}) 通过use方法,传递属性为lang的自定义取localStroge的字段。

Vue.use(Vue2_ts_components,{lang: '__current__lang'})

此时,内部组件将通过 stroge中的__current__lang 来判定当前使用环境

可用模块

为方便你对组件配置项类型、可选参数方便观看,提供了组件内部的公共TS文件,你可以引入node_modules里面的ts声明文件,来帮助你快速的使用组件

import {
	IPagination,
	ISearch,
	ITableConfig,
	ITableColumnConfig,
	IOptions,
	IFormSearch,
	IHandle,
	IResponse
} from 'vue2_ts_components/src/ts/comm';
TS类型说明备注
IPagination分页类型
ISearch搜索组件点击查询、重置时,返回的数据类型
ITableConfig表格总体配置
ITableColumnConfig单元格配置
IOptionsSelect框 options类型
IFormSearch搜索 框类型
IHandle新增、编辑时,操作类型
IResponse接口响应数据

可用组件列表

表格(已集成分页)

使用

支持element-ui Table上所有属性和方法

当组件配置与element-ui table上的属性共同存在时,组件配置项优先于table上的属性

TableComponent内部已设定高频使用表格的配置配置参数,你可以先不传tableConfig配置,来观察是否满足你的预期,如果不满足再进行自定义配置,这将提高你的开发效果

<TableComponent
      :tableData="tableData"
      :tableColumnConfig="tableColumnConfig"
      @getSelectRow="getSelectRow"
    >
        <!-- 表格头部操作栏  slotName不可变 -->
        <template #batchHandle="{data}">
            <el-button type="danger" @click="deleteItem(data)">批量删除</el-button>
       <!-- <el-button type="danger" @click="deleteItem(data)">新增</el-button>
            <el-button type="danger" @click="deleteItem(data)">编辑</el-button>
            <el-button type="danger" @click="deleteItem(data)">其它</el-button> -->
        </template>
        
        <!-- 自定义时间  -->
         <template #date="{data}">
           <p @click="showData(data)">{{data.date.replaceAll('-','/')}}</p>
        </template>
        
        <!-- 操作栏按钮slot  -->
        <template #handle="data">
            <el-button type="danger" @click="deleteItem(data)">删除</el-button>
        </template>
        
  </TableComponent>
  <script>
  tableConfig = {
      indexWidth: 120
  };
  tableColumnConfig = [
    {
       title: '标题',
       key: 'title'
    },
     {
       title: '日期',
       key: 'date'
    },
  ];
</script>
预览

npm.io

tableConfig 配置项

参数说明默认值可选值
tableConfig.border是否有border边线boolean型默认true
tableConfig .stripe是否有隔行纹理boolean型默认true
tableConfig.maxHeight表格最大高度,超过时将出现滚动条number型默认800
tableConfig.selection是否带有选择框,boolean型,默认值:true默认true
tableConfig.tableLayout表格分布方式
tableConfig .selectionFixed选择框固定位置string型left/right/true/false
config.rowClassNamestring型
config.indexMethod序号自定义下标,返回一个numberNumber型
config.indexWidth序号显示宽度Number80
config.cellClassNamestring型
config.showPagination是否带有分页组件boolean型默认true
config.showIndex是否带有下标序号列boolean型默认true
config.custormClass自定义表格classstring型
config.selectable选择框可选条件Fuction型,返回一个boolean
@getSelectRow选中的记录

tableColumnConfig配置项

参数说明默认值可选值
tableColumnConfig.title单元格标题string型
tableColumnConfig .key绑定的属性,需要展示的值 字段string型
tableColumnConfig.sortable是否带有排序功能boolean型
tableColumnConfig.width单元格宽度string | number型
tableColumnConfig.fixed固定当前列string | boolean
tableColumnConfig .isMoney是否是金额,true会将数字转千分位展示boolean型

tableAttributes 可配置element-ui table自带属性,优秀级低级当前组件属性和方法

详细参考Element-ui https://element.eleme.io/#/zh-CN/component/table Table Attributess配置参数

<TableComponent :tableAttributes="{size: 'mini'}"></<TableComponent>

tableEvents 可配置element-ui table自带方法,优秀级低级当前组件属性和方法

<TableComponent 
        :tableEvents="{
                      select: (selection, row)=>{},
                      selection-change:(selection)=>{}}"
>
</<TableComponent>

loading 表格加载动画

<TableComponent :loading="loadingStatus"></<TableComponent>

paginationData 表格分页自定义配置参数

此外配置具体参数与【分页封装】配置项完全相同,请参数上面分页封装,如果需要隐藏分页可通过config.showPagination = false完成

搜索栏

使用
<FormGroup
      :formConfig="formConfig"
      ref="formItemGroup"
      @getFormData="getFormData"
    >
      <template #default="scope">
        <div class="handle-btn">
          <el-button
            size="small"
            icon="el-icon-refresh-left"
            type="default"
            @click="scope.reset"
            >{{ $t("重置") }}</el-button
          >
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="scope.search"
            >{{ $t("查询") }}</el-button
          >
        </div>
      </template>
    </FormGroup>
详细事例
  formConfig: IFormSearch[] = [
    {
      label: '公司',
      key: "company",
      type: "selectRemoteMethod",
      span: 6,
      multiple: true,
      collapseTags: true,
      loadApi: async (params) => {
        const data = await axios.post(url) || []
        return data;
      },
    },
    {
      label: '学校',
      key: "school",
      type: "radio",
      span: 6,
      multiple: true,
      collapseTags: true,
      value: 1,
      loadApi: [
          {label: '重庆大学', value: 1},
          {label: '北京大学', value: 2}
      ],
       onChange: ({formData, formList, index, e}: any, that: any)=>{
    	   that.formData['curShool'] = e;	
      }
    },
    {
        label: '当前学校',
        key: 'curSchool',
        type: 'input',
        span: 6,
        // 自定义element原生控制
        elementAttributes:{
            "show-password": true
        }
    }
        
   ];
预览

npm.io

formConfig[] 配置

参数说明备注
formConfig.label展示label
formConfig.textAlign展示label对齐方式可选'left','center','right'
formConfig.labelWidth展示label文字的宽度Number类型,默认100
formConfig.formItemWidthinput/select...宽度Number
formConfig.key绑定的值字段 即v-model=""必填
formConfig.type组件类型inputselectselectAsyncradiocheckboxdatedateRangedateTimedateTimeRangemonthselectRemoteMethod
formConfig.value初始绑定的值
require必填默认false,true时,必填不满足时,不向上提交 事件
formConfig.size操作框大小默认small
formConfig.optionstype='select'时,列表配置options: { label: "男", value: "1" }, { label: "女", value: "2" },
formConfig.remoteMethodtype="select/selectAsync"时,远程调接口动态搜索函数需要返回值 (formList, index, text) =>{ formList:是当前配置列表 index当前 配置项的下标 text当前输入的值 }
formConfig.span布局与el-row>el-col :span相同可选1-24,如8时,表示一行展示3列
formConfig.placeholderplaceholder提示信息
formConfig.clearable是否展示清除按钮Boolean类型,默认true
formConfig.multipletype="select/selectAsync"时,是否可以多选列表Boolean类型,默认false
formConfig.collapseTagstype="select/selectAsync"且多选时,多选项是否折叠参考:https://element-plus.gitee.io/zh-CN/component/select.html#select-%E5%B1%9E%E6%80%A7
formConfig.loadApiselect异步时,可调用接口获取列表当数据列表来源于后台接口时,配置loadApi,底层将自动调用,并为options赋值
formConfig.rangSeparatortype="dateRange/dateTimeRange"时,分割符默认'-'
formConfig.startPlaceholder时间、日期范围选择时,开始时间的placeholder
formConfig.endPlaceholder时间、日期范围选择时,结束时间的placeholder
formConfig.valueFormat日期框返回的格式默认yyyy-MM-dd
formConfig.disabledDate日期禁用项配置
formConfig.onChange({formData, formList, index, e}: any, that: any)=>{}formData(当前表单整体数据),formList(配置项列表),index(下标),e(输入的内容)that为当前组件实例
formConfig.onBlur({formData, formList, index, e}: any, that: any)=>{}formData(当前表单整体数据),formList(配置项列表),index(下标),e(输入的内容)that为当前组件实例
formConfig.onFocus({formData, formList, index, e}: any, that: any)=>{}formData(当前表单整体数据),formList(配置项列表),index(下标),e(输入的内容)that为当前组件实例
formConfig.elementAttributeselement操作框原生属性
formConfig.syncResetFormData异步设置表单中的值假如搜索框内容默认值全部来源于接口此时通过异步syncResetFormData = {name: 'xxx',age:xx}这将很用用

金额输入框

使用

与普通输入框相同,在此增加千分位展示

<MoneyInput v-model="money"></MoneyInput>

http://server.yuhongshao.cn/static/yuhongshao/20230505171413.gif

参数配置

与element-ui Input框完全相同

标题

使用
<TableTitle title="查询条件" themeColor="orange"></TableTitle>
参数说明默认值
title展示的文字查询
themeColor主题颜色#2c75ec
预览

npm.io

远程单选多选搜索

使用
   <RemoteMethodSelect
              v-model="name"
              :loadApi="getNameFunction"
              @getFullData="getFullData"
   ></RemoteMethodSelect>
<script>
  new Vue({
      methods:{
          /**
            * params为远程搜索输入关键字
            * @pamra { object } params;
          **/
          async getNameFunction(params){
              const result =  axios.get(url,pamras);
              /** 请返回一个带有label  and value 两个字段的数据  **/
              return result.map(item=>({
                  label: item.text,
                  value: item.id
              }));
          }
      }
  })
</script>
参数说明默认值
所有参数与elementui select相同size=small,clearable= true,filterable= true

分页封装

使用
 <PaginationComponent :config="config" @getPaginationData="getPaginationData">
 </PaginationComponent>
参数说明默认值
config.currentPage当前页Number型,默认值:1
config.pageSize分页展示的数量Number型,默认值:10
config.pageSizes每页显示个数选择器的选项设置Number[]型,默认值:10, 20, 30, 50, 100
config.total数据总数Number型,默认值:0
config.small是否使用小型分页样式Boolean型,默认值:false
config.background是否为分页按钮添加背景色Boolean型,默认值:true
config.disabled是否禁用分页Boolean型,默认值:false
config.layout组件布局,子组件名用逗号分隔String型,默认值:"total, prev, pager, next,sizes, jumper"
config.align分页组件对齐方式String型,默认值“right",支持"left/center/right"
config.attributes分页组件原生element pagination自带属性Object, 参考 attributes = {currentPage: 1,xxx:2}
@getPaginationData分页数量、当前页变化时触发({currentPage,pageSize})=>{}
预览

npm.io

上传文件

使用
<UploadGroup
          :fn="uploadFile"
          :title="上传导入"
          :callBack="uploadFileResponse"
        ></UploadGroup>

<script>
 // 封装的ajax
 const custormAxios = (file,onUploadProgress){
        return  axios.create({
   			 baseURL: '/', // 如果url不是绝对路径,那么会将baseURL和url拼接作为请求的接口地址,用来区分不同环境,
    		 timeout: 60000, // 请求超时时间
   			 responseType: 'json', // 表示服务器响应的数据类型
    		 onUploadProgress: function (progressEvent) {
      			// 对原生进度事件的处理
      		    onUploadProgress ? onUploadProgress(progressEvent): ()=>{}
    		},
        }
    

new Vue({
    methods:{
        uploadFile(files,onUploadProgress){
           // 调用自己的ajax,onUploadProgress请在ajax中的上传进度事件中调用
            custormAxios(file,onUploadProgress)
        },
        uploadFileResponse(responseData){
            // 接口响应回来的数据
        }
    }
})
</script>
参数说明默认值
title上传按钮展示的文字string
disabled上传按钮是否禁用boolean型
fn导入调用的接口请求Function型
uploadFileExt导入文件允许的后缀string[],默认"xlsx", "xls"
config.total数据总数Number型,默认值:0
callBack回调函数,文件上传完成 后返回接口返回的数据Function型
预览

http://server.yuhongshao.cn/static/yuhongshao/20230324141835.png

其它问题

Q:两个及以上的搜索框依赖于同一个数据?

现有如下配置,公司1、公司2共同使用后台同一个接口,如果直接配置,会出现页面调用两次http://xxx.com/list

  formConfig: IFormSearch[] = [
    {
      label: 公司1,
      key: "company",
      type: "selectRemoteMethod",
      span: 6,
      multiple: true,
      collapseTags: true,
      loadApi: async (params) => {
        const data = await axios.post('http://xxx.com/list') || []
        return data;
      },
    },
    {
      label: 公司2,
      key: "company",
      type: "selectRemoteMethod",
      span: 6,
      multiple: true,
      collapseTags: true,
      loadApi: async (params) => {
        const data = await axios.post('http://xxx.com/list') || []
        return data;
      },
    }
   ]

为避免这种情况,你可以调用代码如下

  formConfig: IFormSearch[] = [
    {
      label: 公司1,
      key: "company",
      type: "selectRemoteMethod",
      span: 6,
      multiple: true,
      collapseTags: true,
      loadApi: async (params) => {
        const data = await this.getList();
        return data;
      },
    },
    {
      label: 公司2,
      key: "company",
      type: "selectRemoteMethod",
      span: 6,
      multiple: true,
      collapseTags: true,
      loadApi: async (params) => {
        const data = await this.getList();
        return data;
      },
    }
   ]
  // data中定义存放变量
  companyList: any = [];

  public async getList(){
      // 已经存在,直接返回数据
      if(this.companyList){
          return this.companyList
      }
      // 不存在,请求接口
      const data  = await axios.post('http://xx.com/list');
      this.companyList = data;
      return data;
  }

其它异常

由于工作原因测试不足,可能存在异常情况,如某些功能异常

如果你已经使用了这套组件遇到了问题,可通过QQ: 1045749725与我联系,我将尽量解决你的问题和补充所需功能

1.2.1

2 years ago

1.2.0

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago