ant design pro for vue
1、定制主题
src/config/defaultSettings.js
2、主体布局
src/layout/BasicLayout.vue
3、定制主题
https://www.antdv.com/docs/vue/customize-theme-cn/
项目根目录下新建文件vue.config.js
JavaScript Code复制内容到剪贴板
- // vue.config.js
- module.exports = {
- css: {
- loaderOptions: {
- less: {
- modifyVars: {
- 'primary-color': '#1DA57A',
- 'link-color': '#1DA57A',
- 'border-radius-base': '2px',
- },
- javascriptEnabled: true,
- },
- },
- },
- };
4、vue-cil3 运行报错 --- warnings potentially fixable with the `--fix` option
vue.config.js,找到
JavaScript Code复制内容到剪贴板
- // lintOnSave:{ type:Boolean default:true } 问你是否使用eslint
- lintOnSave: false,
添加新路由
1、引入页面
/src/router/generator-routers.js
2、添加路由
/src/config/router.config.js
3、如果是mock数据,修改用户权限
/src/mock/services/user.js
a-select,绑定的value必须是string类型,否则会报错,如果是Number类型,可以用toString转一下,同样的赋值的时候,也需要将它赋值为String
XML/HTML Code复制内容到剪贴板
- <a-select
- mode="tags"
- placeholder="请选择负责人"
- v-decorator="['leader',{rules: [{ required: true, message: '负责人不可为空' }]}]"
- >
- <a-select-option
- v-for="(item) in leaderOptions"
- :key="item.userId"
- :value="item.userId.toString()"
- >{{ item.name }}</a-select-option>
- </a-select>
- const leader = this.model.leaderList ? this.model.leaderList.map(e => {
- return e.userId.toString()
- }) : []
- const fieldsValues = {
- leader: leader
- }
- this.form.setFieldsValue(fieldsValues)
如果a-select需要给一个默认值:
XML/HTML Code复制内容到剪贴板
- <a-select v-decorator="['unit', { initialValue: 'kg' }]" style="width:60px;">
s-table,展开所有的树列表,原有的API defaultExpandAllRows,在场景下并不能生效
PHP Code复制内容到剪贴板
- <s-table
- ref="table"
- rowKey="id"
- :data="loadData"
- childrenColumnName="children"
- :expandedRowKeys="expandedRowKeys"
- ...
- @expand="onExpand"
- >
- export default {
- data () {
- return {
- expandedRowKeys: [], // table展开的行
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- const requestParameters = Object.assign({}, parameter, this.queryParam)
- return departmentList(requestParameters)
- .then(res => {
- const data = this.setItems(res.data.list)
- const result = {
- data: data,
- pageSize: res.data.pageInfoVo.pageSize,
- pageIndex: res.data.pageInfoVo.pageIndex,
- totalCount: res.data.pageInfoVo.total,
- totalPage: res.data.pageInfoVo.totalPage
- }
- // 这里是写了一个方法,从树列表中获取所有的id,然后赋值
- const ids = getTreeListId(data)
- this.expandedRowKeys = ids
- return result
- })
- },
- },
- computed: {
- rowSelection () {
- return {
- selectedRowKeys: this.selectedRowKeys,
- onChange: this.onSelectChange
- }
- }
- },
- methods: {
- onExpand (expanded, record) {
- console.log('extend:' + expanded)
- console.log('record: ' + JSON.stringify(record))
- if (expanded) {
- // 设置展开窗Key,代表展开操作
- this.expandedRowKeys.push(record.id)
- } else {
- // 代表折叠操作
- if (this.expandedRowKeys.length) {
- thisthis.expandedRowKeys = this.expandedRowKeys.filter(v => {
- return v !== record.id
- })
- }
- }
- },
JavaScript Code复制内容到剪贴板
- /**
- * 根据树列表,获取所有的id值
- * @param {*} data 树列表
- * @param {*} field 需要取的字段名,如id
- * @param {*} children 子级的字段名,如children
- * @param {*} arr 返回的id集合,默认为空
- * @returns
- */
- export function getTreeListId (data, field = 'id', children = 'children', arr = []) {
- for (const item of data) {
- arr.push(item[field])
- if (item[children] && item[children].length) getTreeListId(item[children], field, children, arr)
- }
- return arr
- }
- /**
- * 处理children没有值的时候,将其置为空
- * @param {*} data
- * @param {*} children
- * @returns
- */
- export function processTreeChildren (data, children = 'children') {
- return data.map((item, index) => {
- if (item[children].length > 0) {
- processTreeChildren(item[children])
- } else {
- delete item[children]
- }
- return item
- })
- }
Vue-router-link跳转页面时不在顶部问题解决
在router文件夹下的index.js文件中添加一段代码
XML/HTML Code复制内容到剪贴板
- scrollBehavior (to, from, saveTop) {
- if (saveTop) {
- return saveTop
- } else {
- return { x: 0, y: 0 }
- }
- }
antdv 表格组件
1、在src/components下面解压ProTable
2、修改src/components下面的index.js,将ProTable仿着STable加进去
3、视图
PHP Code复制内容到剪贴板
- import {Ellipsis, ProTable } from '@/components'
- export default {
- components: {
- Ellipsis,
- ProTable
- },
XML/HTML Code复制内容到剪贴板
- <a-card :bordered="false" style="margin-top:20px;">
- <pro-table
- ref="table"
- size="default"
- childrenColumnName="childs"
- rowKey="id"
- :showPagination="true"
- :columns="columns"
- :data="loadData"
- :alert="false"
- :rowSelection="rowSelection"
- :tableListItem="{key:'number',status: 'string | number'}"
- :settings="{indeterminate:true,checkAll:true,defaultChecked:['a1','a4']}"
- @clickSettingColumns="clickTableSettingColumns"
- >
- <div slot="toolBar">
- <a-button type="primary">
- 新建
- </a-button>
- </div>
- <span slot="result" slot-scope="text">
- <a-badge :status="text | typeColorFilter" :text="text | typeTextFilter" />
- </span>
- <span slot="serial" slot-scope="text, record, index">
- {{ index + 1 }}
- </span>
- <span slot="action" slot-scope="text, record">
- <template>
- <a @click="handleEdit(record)">编辑</a>
- <a-divider type="vertical" />
- <a @click="handleDelete(record)">删除</a>
- </template>
- </span>
- </pro-table>
- </a-card>
antdv 筛选组件支持单选,多选
a-switch 开关组件
XML/HTML Code复制内容到剪贴板
- <a-switch checked-children="是" un-checked-children="否" @change="onChangeSwitch" v-model="showChildren" />
- <script>
- ...
- methods: {
- onChangeSwitch (e) {
- this.showChildren = e
- },
- }
- </script>
XML/HTML Code复制内容到剪贴板
- <a-switch checked-children="开" un-checked-children="关" :defaultChecked="record.status === 1" @change="(e) => changeStatus(e, record)" />
- <script>
- ...
- methods: {
- changeStatus (checked, record) {
- // do something
- },
- }
- </script>
上一篇 mint ui cell