mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-11-02 07:50:37 +00:00
feat: 生成列表
This commit is contained in:
parent
0ce7b98c36
commit
16e67e0c90
51
template/admin/src/api/crud.js
Normal file
51
template/admin/src/api/crud.js
Normal file
@ -0,0 +1,51 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
import request from '@/libs/request';
|
||||
|
||||
/**
|
||||
* @description 获取接口配置
|
||||
* @param {Object} param data {Object} 传值参数
|
||||
*/
|
||||
export function crudApi(table_name) {
|
||||
return request({
|
||||
url: `system/crud/config/${table_name}`,
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 列表接口
|
||||
*/
|
||||
export function getList(url, params) {
|
||||
return request({
|
||||
url: url,
|
||||
method: 'get',
|
||||
params,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @description 创建接口
|
||||
*/
|
||||
export function getCreateApi(url) {
|
||||
return request({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @description 创建接口
|
||||
*/
|
||||
export function getEditApi(url) {
|
||||
return request({
|
||||
url: url,
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
141
template/admin/src/pages/crud/index.vue
Normal file
141
template/admin/src/pages/crud/index.vue
Normal file
@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div>
|
||||
<Card :bordered="false" dis-hover class="ivu-mt">
|
||||
<Row type="flex">
|
||||
<Col v-bind="grid">
|
||||
<Button type="primary" icon="md-add" @click="add">添加</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data="dataList"
|
||||
ref="table"
|
||||
class="mt25"
|
||||
:loading="loading"
|
||||
highlight-row
|
||||
no-userFrom-text="暂无数据"
|
||||
no-filtered-userFrom-text="暂无筛选结果"
|
||||
>
|
||||
<template slot-scope="{ row, index }" slot="action">
|
||||
<a @click="edit(row)">修改</a>
|
||||
<Divider type="vertical" />
|
||||
<a @click="del(row, '删除', index)">删除</a>
|
||||
</template>
|
||||
</Table>
|
||||
<div class="acea-row row-right page">
|
||||
<Page :total="total" show-elevator show-total @on-change="pageChange" :page-size="from.limit" />
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex';
|
||||
import { crudApi, getList, getCreateApi, getEditApi } from '@/api/crud.js';
|
||||
|
||||
export default {
|
||||
name: 'user_recharge',
|
||||
data() {
|
||||
return {
|
||||
grid: {
|
||||
xl: 7,
|
||||
lg: 7,
|
||||
md: 12,
|
||||
sm: 24,
|
||||
xs: 24,
|
||||
},
|
||||
loading: false,
|
||||
columns: [],
|
||||
from: {
|
||||
page: 1,
|
||||
limit: 15,
|
||||
},
|
||||
dataList: [],
|
||||
total: 0,
|
||||
methodApi: {},
|
||||
curdKey: '',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState('media', ['isMobile']),
|
||||
labelWidth() {
|
||||
return this.isMobile ? undefined : 75;
|
||||
},
|
||||
labelPosition() {
|
||||
return this.isMobile ? 'top' : 'left';
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.getCrudApi(this.$route.params.table_name);
|
||||
},
|
||||
methods: {
|
||||
getCrudApi(tableName) {
|
||||
crudApi(tableName).then((res) => {
|
||||
this.methodApi = res.data.route;
|
||||
this.curdKey = res.data.key;
|
||||
res.data.columns.push({
|
||||
title: '操作',
|
||||
slot: 'action',
|
||||
fixed: 'right',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
});
|
||||
this.columns = res.data.columns;
|
||||
this.getList();
|
||||
});
|
||||
},
|
||||
// 添加
|
||||
add() {
|
||||
let url = this.methodApi.create;
|
||||
this.$modalForm(getCreateApi(url)).then(() => this.getList());
|
||||
},
|
||||
//列表
|
||||
getList() {
|
||||
this.loading = true;
|
||||
let url = this.methodApi.index;
|
||||
getList(url, this.from)
|
||||
.then(async (res) => {
|
||||
let data = res.data;
|
||||
this.dataList = data.list;
|
||||
this.total = data.count;
|
||||
this.loading = false;
|
||||
})
|
||||
.catch((res) => {
|
||||
this.loading = false;
|
||||
this.$Message.error(res.msg);
|
||||
});
|
||||
},
|
||||
//分页
|
||||
pageChange(index) {
|
||||
this.from.page = index;
|
||||
this.getList();
|
||||
},
|
||||
// 修改
|
||||
edit(row) {
|
||||
let url = this.methodApi.edit.replace('<id>', row[this.curdKey]);
|
||||
this.$modalForm(getEditApi(url)).then(() => this.getList());
|
||||
},
|
||||
// 删除
|
||||
del(row, tit, num) {
|
||||
let url = this.methodApi.delete.replace('<id>', row[this.curdKey]);
|
||||
let delfromData = {
|
||||
title: tit,
|
||||
num: num,
|
||||
url: url,
|
||||
method: 'DELETE',
|
||||
ids: '',
|
||||
};
|
||||
this.$modalSure(delfromData)
|
||||
.then((res) => {
|
||||
this.$Message.success(res.msg);
|
||||
this.getList();
|
||||
})
|
||||
.catch((res) => {
|
||||
this.$Message.error(res.msg);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="stylus"></style>
|
||||
39
template/admin/src/router/modules/crud.js
Normal file
39
template/admin/src/router/modules/crud.js
Normal file
@ -0,0 +1,39 @@
|
||||
// +---------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +---------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +---------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +---------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +---------------------------------------------------------------------
|
||||
|
||||
import LayoutMain from '@/layout';
|
||||
import setting from '@/setting';
|
||||
let routePre = setting.routePre;
|
||||
|
||||
const pre = 'crud_';
|
||||
|
||||
export default {
|
||||
path: routePre + '/crud',
|
||||
name: 'crud',
|
||||
header: 'crud',
|
||||
redirect: {
|
||||
name: `${pre}crud`,
|
||||
},
|
||||
meta: {
|
||||
auth: ['admin-crud'],
|
||||
},
|
||||
component: LayoutMain,
|
||||
children: [
|
||||
{
|
||||
path: ':table_name',
|
||||
name: `${pre}crud`,
|
||||
meta: {
|
||||
auth: ['admin-crund-index'],
|
||||
title: '增删改查',
|
||||
},
|
||||
component: () => import('@/pages/crud/index'),
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -25,15 +25,16 @@ import statistic from './modules/statistic';
|
||||
import frameOut from './modules/frameOut';
|
||||
import division from './modules/division';
|
||||
import settings from '@/setting';
|
||||
import crud from './modules/crud';
|
||||
|
||||
const modulesFiles = require.context('./modules/crud', true, /\.js$/)
|
||||
const modulesFiles = require.context('./modules/crud', true, /\.js$/);
|
||||
|
||||
const routers = []
|
||||
const routers = [];
|
||||
// 将扫描到的路由信息加入路由数组中
|
||||
modulesFiles.keys().forEach(modulePath => {
|
||||
const value = modulesFiles(modulePath)
|
||||
routers.push(value.default)
|
||||
})
|
||||
modulesFiles.keys().forEach((modulePath) => {
|
||||
const value = modulesFiles(modulePath);
|
||||
routers.push(value.default);
|
||||
});
|
||||
|
||||
let routePre = settings.routePre;
|
||||
/**
|
||||
@ -169,7 +170,8 @@ const frameIn = [
|
||||
app,
|
||||
statistic,
|
||||
division,
|
||||
...routers
|
||||
...routers,
|
||||
crud,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user