Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
434 changes: 172 additions & 262 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
"build": "vue-cli-service build"
},
"dependencies": {
"ag-grid-community": "^23.2.1",
"ag-grid-vue": "^23.2.1",
"axios": "^0.19.0",
"babel-polyfill": "^6.26.0",
"core-js": "^2.6.5",
"echarts": "^4.3.0",
"mockjs": "^1.0.1-beta3",
"moment": "^2.24.0",
"sass": "^1.26.10",
"sass-loader": "^9.0.2",
"shallow-clone": "^3.0.1",
"view-design": "^4.0.0",
"vue": "^2.6.10",
"vue-class-component": "^7.2.5",
"vue-property-decorator": "^9.0.0",
"vue-router": "^3.0.3",
"vuex": "^3.0.1",
"wangeditor": "^3.1.1"
Expand Down
6 changes: 5 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
</div>
</template>
<script>
export default {
}
</script>
<style lang="less">
<style lang="scss">
@import "../node_modules/ag-grid-community/dist/styles/ag-grid.css";
@import "../node_modules/ag-grid-community/dist/styles/ag-theme-alpine.css";
</style>
97 changes: 97 additions & 0 deletions src/components/AgGrid/AgGridActionCell.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<template>
<div class="icon-list">
<div v-for="action in filterActionCellList" :key="action.actionId" @click="() => activeModal(action)">
<Icon :title="action.name" :size="20" :type="action.icon" />
<ModalMiddleWare
:propsList="action.propsList"
:active.sync="action.active"
:title="action.name"
:component-id="action.id"
:component-name="action.component"
:component-url="action.componentUrl"
:prop-list="action.propsList"
></ModalMiddleWare>
</div>
</div>
</template>

<script>
import ModalMiddleWare from "./ModalMiddleWare";
import Vue from 'vue'
import { transPropsListByProps, dynamicSetComponent } from './AgGridUtil'
export default {
name: "AgGridActionCell",
data() {
return {
active: false,
title: 'action cell modal title',
paramsData: null,
actionCellList: [],
}
},
computed: {
filterActionCellList() {
if(this.actionCellList.length > 0) return this.actionCellList.filter(e => e.renderFlag && e.component)
return []
}
},
components: {
ModalMiddleWare,
},
methods: {
showParams() {
console.log('params', this.params)
this.active = true
},
activeModal(action) {
dynamicSetComponent(action.componentName, action.componentUrl, () => {
this.$set(action, 'active', true)
})
},
okClick() {
console.log('action cell ok click')
},
cancelClick() {
console.log('action cell cancel click')
},
init() {
this.paramsData = this.params.data
if(this.params && this.params.frameworkComponentWrapper && this.params.frameworkComponentWrapper.parent) {
const { $vnode } = this.params.frameworkComponentWrapper.parent
if($vnode) {
const { actionColumn } = $vnode.context
this.actionCellList = actionColumn.map(e => {
let propsList = {}
const actionId = `${e.id}-${this.paramsData.id}`
let { renderFlag, props } = e
props = props()
if(props.length > 0) propsList = transPropsListByProps(this.paramsData, props)
if(typeof renderFlag === 'function') renderFlag = renderFlag(this.paramsData)
const data = {...e}
this.$set(data, 'actionId', actionId)
this.$set(data, 'renderFlag', renderFlag)
this.$set(data, 'propsList', propsList)
// console.log('data', data)
return data
// return {
// ...e,
// actionId,
// renderFlag,
// propsList,
// }
})
}
}
}
},
created() {
this.init()
}
}
</script>

<style lang="scss">
.icon-list {
display: inline-flex;
}
</style>
12 changes: 12 additions & 0 deletions src/components/AgGrid/AgGridListComponentList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AgGridVue } from "ag-grid-vue"
import ModalMiddleWare from "./ModalMiddleWare";
import AgGridActionCell from "./AgGridActionCell";
// import TestForm from "./TestForm";
export default {
AgGridVue,
// modal中间动态组件渲染组件
ModalMiddleWare,
// 快速操作列渲染组件
AgGridActionCell,
// TestForm: () => import('./TestForm'),
}
41 changes: 41 additions & 0 deletions src/components/AgGrid/AgGridUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Vue from 'vue'

/**
* 根据props将paramsData转换成带有指定属性和属性值的对象
* @param {Object} paramsData 被转换的数据
* @param {Array} props 指定生成对象的属性值的对象数组(或者字符串)
*
* */
export const transPropsListByProps = (paramsData, props) => {
const propsList = {}
if(props.length === 0 || !props) return propsList
props.forEach(e => {
if(typeof e === 'object') {
const { tag, required } = e
if(!!tag && !!required) {
Object.defineProperty(propsList, required, {value: paramsData[tag]})
} else if(!required && !!tag) {
Object.defineProperty(propsList, tag, {value: paramsData[tag]})
}
} else {
Object.defineProperty(propsList, e, {value: paramsData[e]})
}
})
return propsList
}

/**
* 动态注入表单组件
* @param {String} componentUrl 组件相对地址
* @param {Function} callBack 组件注入成功后的回调函数
*
* */
export const dynamicSetComponent = async (componentName, componentUrl, callBack) => {
const requireComponent = async () => {
const component = require(`@/${componentUrl}`)
Vue.component(component.default.name, component.default)
console.log(component.default.name, component.default)
}
await requireComponent()
callBack && callBack()
}
172 changes: 172 additions & 0 deletions src/components/AgGrid/AgGridView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<template>
<AgGridViewList style="width: 100%; height: 100%;"
class="ag-theme-alpine"
:columnDefs="columnDefs"
:dataList="rowData"
:dropDownMenu="dropDownMenu"
:actionColumn="actionColumn">
</AgGridViewList>
</template>

<script>
import AgGridViewList from "./AgGridViewList";
import componentsList from "./AgGridListComponentList";

export default {
name: "AgGridView",
data() {
return {
columnDefs: null,
rowData: null,
dropDownMenu: [
{
id: "TestForm",
name: "测试按钮1",
component: "TestForm",
componentUrl: "components/AgGrid/TestForm",
permission: 'system:addSensorType',
type: 'info',
buttonColor: 'success',
active: false,
propsList: {
message: 'hello',
phoneNumber: 132009090909,
},
event: function() {
}
},
{
id: "DeleteSensorType",
name: "测试按钮2",
component: null,
type: 'error',
buttonColor: 'error',
permission: 'system:deleteSensorType',
content: '删除传感器',
propsList: {
accept: () => {
console.log('accept')
},
cancel: () => {
console.log('cancel')
}
},
event: () => {
// this.$renderModal('info', '删除传感器')
}
}
],
actionColumn: [
{
id: 'TestForm',
name: "测试按钮1",
component: "TestForm",
componentUrl: "components/AgGrid/TestForm",
permission: 'system:addSensorType',
type: 'info',
active: false,
props: function () {
return [
{
tag: 'make',
required: 'message'
},
{
tag: 'price',
required: 'phoneNumber'
}
]
},
icon: 'ios-create-outline',
renderFlag: (paramsData) => {
const { make } = paramsData
return make === 'Toyota'
},
propsList: {
},
event: function() {
}
},
{
id: 'TestForm2',
name: "测试按钮2",
component: "TestForm2",
componentUrl: "components/AgGrid/TestForm2",
permission: 'system:addSensorType',
type: 'info',
active: false,
props: function () {
return [
{
tag: 'make',
required: 'message'
},
{
tag: 'price',
required: 'phoneNumber'
}
]
},
icon: 'ios-cog-outline',
renderFlag: (paramsData) => {
const { make } = paramsData
return make === 'Toyota'
},
propsList: {
},
event: function() {
}
},
]
}
},
components: {
AgGridViewList
},
beforeMount() {
this.columnDefs = [
{headerName: 'Make', field: 'make'},
{headerName: 'Model', field: 'model'},
{headerName: 'Price', field: 'price'}
];

this.rowData = [
{make: 'Toyota', model: 'Celica', price: 35000, id: 1,},
{make: 'Ford', model: 'Mondeo', price: 32000, id: 2,},
{make: 'Porsche', model: 'Boxter', price: 72000, id: 3},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},
// {make: 'Toyota', model: 'Celica', price: 35000},
// {make: 'Ford', model: 'Mondeo', price: 32000},
// {make: 'Porsche', model: 'Boxter', price: 72000},

];
},
}
</script>

<style scoped>

</style>
Loading