1.5.9 • Published 2 years ago

gy-vue-pkg v1.5.9

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

gy-vue-pkg

谷雨公司前端沉淀产物,基于Vue2.X,AntdUI封装项目常用公共组件

安装

NPM

npm install gy-vue-pkg

Yarn

yarn add gy-vue-pkg

使用上手

// 该插件依赖 antd UI框架
1. 安装依赖
yarn add ant-design-vue 
yarn add gy-vue-pkg
2.引入
import Vue from "vue";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import gypkg from "gy-vue-pkg";
3.注册插件
Vue.use(Antd); 
Vue.use(gypkg); // 注册插件 注册全局组件

案列

  • App.vue

    语言国际化配置 zh_CN

    <template>
      <a-config-provider :locale="zh_CN">
        <div id="app">
          <router-view />
        </div>
      </a-config-provider>
    </template>
    <script>
    import zh_CN from "ant-design-vue/es/locale/zh_CN";
    export default {
      name: "app",
      data() {
        return {
          zh_CN
        };
      }
    };
    </script>
  • pageLayout.vue

    引用页面整体布局

    <template>
      <gy-manageLayout
        :menuData="menuData"
        userName="admin"
        title="微信后台管理系统"
        :logo="logo"
        class="mg_layout"
      ></gy-manageLayout>
    </template>
    
    <script>
    export default {
      name: "ManageLayout",
      data() {
        return {
          logo: require("public/logo.png"),
          menuData: [
            {
              icon: "environment",
              title: "菜单管理",
              router: "MenuManage",
              noCheckRoles: true
            },
            {
              icon: "appstore",
              title: "地区管理",
              router: "DistrictManage"
            },
            {
              icon: "pie-chart",
              title: "资讯管理",
              router: "Information"
            },
            {
              icon: "book",
              title: "用户反馈",
              router: "down"
            }
          ]
        };
      }
    };
    </script>
  • router.js

    import Vue from "vue";
    import VueRouter from "vue-router";
    // 解决页面跳转Vue-Router的Uncaught (in promise)问题
    try {
      const originalPush = VueRouter.prototype.push;
      VueRouter.prototype.push = function push(location) {
        return originalPush.call(this, location).catch(err => err);
      };
    } catch (e) {
      console.log(e);
    }
    Vue.use(VueRouter);
    
    const routes = [
      {
        path: "/",
        component: () =>
          import(
            /* webpackChunkName: "pageLyout" */ "@/components/layouts/pageLyout"
          ),
        children: [
          {
            path: "/",
            name: "MenuManage",
            component: () =>
              import(/* webpackChunkName: "M_Home" */ "@manage/MenuManage")
          }
        ]
      },
      {
        path: "*",
        redirect: "/"
      }
    ];
    
    const router = new VueRouter({
      mode: "hash",
      base: process.env.BASE_URL,
      routes
    });
    
    export default router;
  • Home.vue

    增删改查页面

    <template>
      <section class="MenuManage">
        <gy-crudTemp
          :searchAttr="searchAttr"
          :tableAttr="tableAttr"
          :load-req="loadReq"
          :search-req="loadReq"
        ></gy-crudTemp>
      </section>
    </template>
    
    <script>
    export default {
      name: "Home",
      data() {
        return {
          searchAttr: {
            searchForm: [{ attr: "tmplName", label: "模板名称", type: "date" }]
          },
          tableAttr: {
            title: "模板列表",
            columns: [
              { title: "序号", customRender: (text, record, index) => ++index },
              {
                title: "模板名称",
                dataIndex: "tmplName",
                customRender: text => <a>{text}</a>
              },
              {
                title: "模板描述",
                dataIndex: "tmplRemark"
              },
              {
                title: "模板排序",
                dataIndex: "tmplSort"
              },
              {
                title: "操作",
                customRender: (text, record) => {
                  console.log(record);
                  return (
                    <a-tag color="#f90" onClick={() => this.handleEdit(record)}>
                      编辑
                    </a-tag>
                  );
                }
              }
            ]
          }
        };
      },
      methods: {
        loadReq(params) {
          console.log(params);
          return Promise.resolve([
            {
              tmplName: "a",
              tmplRemark: "asdasd",
              tmplSort: "asdasdsa"
            },
            {
              tmplName: "1",
              tmplRemark: "asadsasdsadasd",
              tmplSort: "asdaasdasdsdsa"
            }
          ]);
        }
      }
    };
    </script>
  • 图例

1614234375460

组件说明

gy-manageLayout(布局组件)

后台管理系统布局组件

6B79ne.png

使用

<template>
  <gy-manageLayout
    :menuData="menuData"
    userName="admin"
    title="微信后台管理系统"
    :logo="logo"
    class="mg_layout"
  ></gy-manageLayout>
</template>

<script>
export default {
  name: "ManageLayout",
  data() {
    return {
      logo: require("public/logo.png"),
      menuData: [
        {
          icon: "environment",
          title: "菜单管理",
          router: "MenuManage"
        },
        {
          icon: "appstore",
          title: "地区管理",
          router: "DistrictManage"
        },
        {
          icon: "pie-chart",
          title: "资讯管理",
          router: "Information"
        },
        {
          icon: "book",
          title: "用户反馈",
          router: "down"
        }
      ]
    };
  }
};
</script>

Api

属性说明类型默认值
userName登录用户名称string-
title标题string-
logologo(项目文件下的图片请使用模块导入的方式)string-
menuData菜单导航栏详情配置见下表Array[]

事件

事件名称说明回调参数
logout点击退出登录时的回调(event)=>void

menuData配置项

参数说明类型默认值
icon菜单字体图标string-
title菜单标题string-
router路由配置项的name属性string-
children子菜单array-

gy-crudTemp(增删改查)

增删改查组件

6BTvp6.png

使用

<template>
  <section class="MenuManage">
    <gy-crudTemp
      :searchAttr="searchAttr"
      :tableAttr="tableAttr"
      :load-req="loadReq"
      :search-req="loadReq"
    ></gy-crudTemp>
  </section>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      searchAttr: {
        searchForm: [{ attr: "tmplName", label: "模板名称", type: "date" }]
      },
      tableAttr: {
        title: "模板列表",
        columns: [
          { title: "序号", customRender: (text, record, index) => ++index },
          {
            title: "模板名称",
            dataIndex: "tmplName",
            customRender: text => <a>{text}</a>
          },
          {
            title: "模板描述",
            dataIndex: "tmplRemark"
          },
          {
            title: "模板排序",
            dataIndex: "tmplSort"
          },
          {
            title: "操作",
            customRender: (text, record) => {
              console.log(record);
              return (
                <a-tag color="#f90" onClick={() => this.handleEdit(record)}>
                  编辑
                </a-tag>
              );
            }
          }
        ]
      }
    };
  },
  methods: {
    loadReq(params) {
      return Promise.resolve([
        {
          tmplName: "a",
          tmplRemark: "asdasd",
          tmplSort: "asdasdsa"
        },
        {
          tmplName: "1",
          tmplRemark: "asadsasdsadasd",
          tmplSort: "asdaasdasdsdsa"
        }
      ]);
    }
  }
};
</script>

Api

属性说明类型默认值
searchAttr搜索表单配置,详情见下表object-
tableAttr表格配置,详情见下表object-
load-req加载表格数据函数,传入请求参数,返回Pormisefunction(params)=>Promise-
search-req通load-reqarray-
isCreated是否初始化时加载表格数据booleanfalse
renderSearch是否渲染搜索表单booleantrue

事件

事件名称说明回调参数
add点击表格新增按钮回调(event)=>void

组件方法(ref调用)

通过 ref调用组件里的方法

方法名称说明回调参数
getSource加载表格数据(event)=>void

searchAttr配置项

支持 tableModule组件配置项 链接

属性说明类型默认值
searchForm搜索表单项,配置见formItem配置array[]

tableAttr配置项

支持antd table配置项链接

支持 tableModule组件配置项 链接

属性说明类型默认值
title表格标题string-
columns表格列配置,具体配置链接array-

gy-formItem(表单配置)

快速生成表单项

6BTXfx.png

使用

<template>
  <div class="home">
    <gy-formItem :item="item"></gy-formItem>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      item: {
        type: "input",
        attr: "name",
        label: "姓名"
      }
    };
  }
};
</script>

Api

属性说明类型默认值
item表单配置项,详情见下表object-
labelCol标签占用宽度number6
wrapCol内容占用宽度numberlabel ? 16 : 24
marginBtm表单下边距number24

item配置

属性说明类型是否必传
label表单标签名string
attr表单属性string
type表单类型,见下方说明string
required是否必填boolean-
rules自定义表单校验项,配置array-
其它特殊配置项后续补充--

表单项 支持的类型:input(文本输入框)、password(密码框)、textarea(文本域)、switch(开关)、checkbox(复选框)、select(选择器)、date(年月日选择器)、rangePicker(时间区间选择器)、number(数字输入框)、radio(单选框)、customSelect(字典选择器)、numberMoney(金额输入框)、momen(年月日时分秒)、upload(文件)

事件

事件名称说明回调参数
enter键盘回车事件(event)=>void
change表单内容更改(event)=>void

gy-searchModule(搜索组件)

6B7FAA.png

使用

<template>
  <div class="home">
    <gy-searchModule :searchForm="searchForm"></gy-searchModule>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      searchForm: [
        {
          label: "姓名",
          type: "input",
          attr: "name"
        }
      ]
    };
  }
};
</script>

Api

属性说明类型默认值
searchForm表单配置项,参照formItemarray[]
loading加载状态booleanfalse
showReset是否显示重置按钮booleantrue
showSearch是否显示搜索按钮booleantrue
title左上角标题string筛选查询

事件

事件名称说明回调参数
search点击搜索按钮(event)=>void
change表单内容更改(event)=>void
reset点击重置按钮(event)=>void

gy-tableModule(表格组件)

6B7P7d.png

使用

<template>
  <div class="home">
    <gy-tableModule
      title="数据"
      :columns="columns"
      :data-source="dataSource"
    ></gy-tableModule>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      dataSource: [{ name: "小明", age: 18, sex: 1, fun: "game" }],
      columns: [
        {
          title: "姓名",
          dataIndex: "name"
        },
        {
          title: "年龄",
          dataIndex: "age"
        },
        {
          title: "性别",
          dataIndex: "sex",
          customRender: text => (text == 1 ? "男" : "女")
        },
        {
          title: "兴趣",
          dataIndex: "fun"
        }
      ]
    };
  }
};
</script>

Api

属性说明类型默认值
columns表格列配置,配置项array[]
dataSource表格数据array[]
showTitleAction是否显示表格右上角booleantrue
pagination表格分页配置,配置项booleantrue
loading表格加载状态booleanfalse
showHead是否显示表格表头booleantrue
title表格标题string-
rowKey表格选中keystring-
rowSelection表格选中项配置,配置项object-
支持更多配置项参考antd ui表格配置,配置项--

事件

事件名称说明回调参数
add点击新增按钮(event)=>void

插槽

  • tableTitle

    表格右上角

gy-editModal(编辑模态框)

6B7ktI.png

使用

<template>
  <div class="home">
    <gy-editModal title="新增" :formItem="formItem" visible></gy-editModal>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      formItem: [
        {
          type: "input",
          attr: "name",
          label: "姓名"
        },
        {
          type: "password",
          attr: "pwd",
          label: "密码"
        },
        {
          type: "input",
          attr: "age",
          label: "年龄"
        },
        {
          type: "select",
          attr: "sex",
          label: "性别",
          options: [
            {
              title: "男",
              value: 1
            },
            {
              title: "女",
              value: 0
            }
          ]
        }
      ]
    };
  }
};
</script>

Api

属性说明类型默认值
formItem表单配置项,参照formItemarray[]
visible是否显示,支持 .syncbooleanfalse
comp显示类型stringdragModala-drawer
loading加载状态booleanfalse
title标题string-
width宽度number650

事件

事件名称说明回调参数
submit点击保存按钮(event)=>void

组件方法(ref调用)

通过 ref调用组件里的方法

  • handleSetValue(values)

    给模态框表单赋值

  • handleResetFields(close)

    重置表单的值

    close 为true时关闭模块框

插槽

  • title

    左上角标题

gy-dragModal(拖动模态框)

6B7Aht.png

使用

<template>
  <div class="home">
    <gy-dragModal visible>
      <section slot="title">新增</section>
      <gy-formItem
        :item="item"
        v-for="item in formItem"
        :key="item.attr"
      ></gy-formItem>
    </gy-dragModal>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      formItem: [
        {
          type: "input",
          attr: "name",
          label: "姓名"
        },
        {
          type: "password",
          attr: "pwd",
          label: "密码"
        },
        {
          type: "input",
          attr: "age",
          label: "年龄"
        },
        {
          type: "select",
          attr: "sex",
          label: "性别",
          options: [
            {
              title: "男",
              value: 1
            },
            {
              title: "女",
              value: 0
            }
          ]
        }
      ]
    };
  }
};
</script>

Api

属性说明类型默认值
wrapClassclass类名array[]
visible是否显示,支持 .syncbooleanfalse
width宽度number520
top顶部距离number100

事件

事件名称说明回调参数
cancel点击关闭(event)=>void

插槽

  • 默认插槽
  • footer
  • title
1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.2.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago