d3-crud-plus
Version:
d2-admin的d2-crud的扩展
101 lines (97 loc) • 3.54 kB
JavaScript
import Vue from 'vue'
import App from './demo/App.vue'
import requestForMock from './demo/request'
import d2CrudX from 'd2-crud-x'
import { d2CrudPlus } from './index'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false
// 按如下重命名引入可与官方版共存,index.vue中标签用<d2-crud-x />使用加强版
// 不传name,则d2CrudX的标签仍为<d2-crud>,不可与官方版共存
Vue.use(d2CrudX, { name: 'd2-crud-x' })
// Element
Vue.use(ElementUI, {
})
// 引入d2CrudPlus
Vue.use(d2CrudPlus, {
getRemoteDictFunc (url, dict) {
// 此处配置你的字典http请求方法
// 实际使用请改成request
return requestForMock({
url: url,
data: dict.body,
method: 'get'
}).then(ret => {
return ret.data
})
},
commonOption () { // 公共配置
return {
format: {
page: { // page接口返回的数据结构配置,
request: {
current: 'current',
size: 'size'
},
response: {
current: 'current', // 当前页码 ret.data.current
size: 'size', // 当前页码 ret.data.current
// size: (data) => { return data.size }, // 每页条数,ret.data.size, 你也可以配置一个方法,自定义返回
total: 'total', // 总记录数 ret.data.total
records: 'records' // 列表数组 ret.data.records
}
}
},
pageOptions: {
compact: true,
export: {
local: true, // 本地导出,false为服务端导出
title: '导出数据', // 文件名
type: 'excel' // 导出类型,excel 或 cvs
// formatter(row,context){}
}
},
options: {
size: 'small'
},
formOptions: {
closeOnClickModal: true, // 点击对话框背景关闭对话框,实际使用过程中容易误触把对话框关闭,导致输入内容丢失,建议设置为false
nullToBlankStr: true, // 提交修改表单时,将undefined的数据修改为空字符串'',可以解决无法清空字段的问题
defaultSpan: 12 // 默认的表单 span
},
viewOptions: {
disabled: false,
componentType: 'form' // 【form,row】 表单组件 或 行组件展示
},
rowHandle: {
minWidth: 260,
edit: {
type: 'primary'
}
}
}
}
})
// 自定义字段类型示例
d2CrudPlus.util.columnResolve.addTypes({
time2: {
form: { component: { name: 'el-date-picker', props: { type: 'datetime' } } }, // 编辑时支持日期时间
search: { component: { props: { type: 'date' } } }, // 搜索时只支持日期
formatter (row, column, value, index) {
return value + '-->我是自定义字段类型:time2'
},
_handle (column) {
// 此方法主要将column中某些依赖的用户配置的属性放到默认配置中,比如数据字典的配置
if (column.dict != null) {
this.form.component.props.dict = column.dict
this.component.props.dict = column.dict
}
}
}
})
// 修改官方字段类型
const selectType = d2CrudPlus.util.columnResolve.getType('select')
selectType.component.props.color = 'auto' // 修改官方的字段类型,设置select的单元格组件支持自动染色
new Vue({
render: h => h(App)
}).$mount('#app')