增加分类
This commit is contained in:
@@ -26,11 +26,11 @@ class Source extends QfShop
|
||||
];
|
||||
$this->insertFields = [
|
||||
//允许添加的字段列表
|
||||
"title","url","status","is_delete"
|
||||
"source_category_id","title","url","status","is_delete","sort","is_top"
|
||||
];
|
||||
$this->updateFields = [
|
||||
//允许更新的字段列表
|
||||
"title","url","status","is_delete"
|
||||
"source_category_id","title","url","status","is_delete","sort","is_top"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
//添加时必须填写的字段
|
||||
@@ -65,8 +65,11 @@ class Source extends QfShop
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
$map[] = ['is_delete','=',0];
|
||||
if(!empty(input('source_category_id'))){
|
||||
$map[] = ['source_category_id','=',input('source_category_id')];
|
||||
}
|
||||
//从请求中获取排序方式
|
||||
$order = $this->getorderfromRequest();
|
||||
$order = ['is_top' => 'desc','sort' => 'desc','source_id' => 'desc'];
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
@@ -217,6 +220,7 @@ class Source extends QfShop
|
||||
|
||||
//删除这个文件
|
||||
unlink("./uploads/".$saveName);
|
||||
|
||||
// 生成二维码
|
||||
foreach ($excel_array as $k => $v) {
|
||||
$patterns = '/^\d+\.|\d+\-/';
|
||||
@@ -238,6 +242,7 @@ class Source extends QfShop
|
||||
if (empty($res) && $url) {
|
||||
$data[$k]['title'] = $title;
|
||||
$data[$k]['url'] = $url;
|
||||
$data[$k]['source_category_id'] = input('source_category_id')??0;
|
||||
$data[$k]['update_time'] = time();
|
||||
$data[$k]['create_time'] = time();
|
||||
$i++;
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\SourceCategory as SourceCategoryModel;
|
||||
|
||||
class SourceCategory extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//查询列表时允许的字段
|
||||
$this->selectList = "*";
|
||||
//查询详情时允许的字段
|
||||
$this->selectDetail = "*";
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"source_category_id" => "=",
|
||||
"name"=>"like"
|
||||
];
|
||||
$this->insertFields = [
|
||||
//允许添加的字段列表
|
||||
"name","sort","status"
|
||||
];
|
||||
$this->updateFields = [
|
||||
//允许更新的字段列表
|
||||
"name","sort","status"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
//添加时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"name"=>"分类名称必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
//修改时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"name"=>"分类名称必须填写",
|
||||
];
|
||||
$this->model = new SourceCategoryModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表接口
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//查询数据
|
||||
$dataList = $this->model->order('sort', 'desc')->select();
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("没有查询到数据", 404);
|
||||
}
|
||||
return jok('数据加载成功', $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//校验Insert字段是否填写
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Insert数据
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
//添加这行数据
|
||||
$data['create_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$this->model->insertGetId($data);
|
||||
return jok('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//校验Update字段是否填写
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Update数据
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
//根据主键更新这条数据
|
||||
$data['update_time'] = time();
|
||||
$this->model->where("source_category_id", $source_category_id)->update($data);
|
||||
return jok('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->delete();
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->delete();
|
||||
}
|
||||
return jok('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->update([
|
||||
"status" => 1,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->update([
|
||||
"status" => 1,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("禁用成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->update([
|
||||
"status" => 0,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->update([
|
||||
"status" => 0,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("启用成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\api\controller;
|
||||
|
||||
use app\api\QfShop;
|
||||
use app\model\Source as SourceModel;
|
||||
use app\model\SourceCategory as SourceCategoryModel;
|
||||
|
||||
class Search extends QfShop
|
||||
{
|
||||
@@ -34,4 +35,11 @@ class Search extends QfShop
|
||||
$data = $SourceModel->getHot(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
$SourceCategoryModel = new SourceCategoryModel();
|
||||
$data = $SourceCategoryModel->getList(input(''));
|
||||
return jok('获取成功',$data);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -37,6 +37,19 @@ class Source extends QfShop
|
||||
'time' => 'timestamp',
|
||||
];
|
||||
|
||||
/**
|
||||
* hasOne qf_source_category
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return $this
|
||||
->hasOne(SourceCategory::class, 'source_category_id', 'source_category_id')
|
||||
->joinType('left')
|
||||
->field('source_category_id,name');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 获取一个信息
|
||||
@@ -48,8 +61,8 @@ class Source extends QfShop
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 0];
|
||||
$map[] = ['source_id', '=', $data['id']];
|
||||
$field = 'source_id as id,title,url,update_time as time';
|
||||
$result = $this->where($map)->field($field)->find();
|
||||
$field = 'source_id as id,source_category_id,title,url,update_time as time';
|
||||
$result = $this->with('category')->where($map)->field($field)->find();
|
||||
if(!is_null($result)){
|
||||
$result->inc('page_views')->update();
|
||||
}
|
||||
@@ -90,6 +103,10 @@ class Source extends QfShop
|
||||
unset($map[array_search(['is_time', '=', 0], $map)]);
|
||||
}
|
||||
|
||||
if(!empty($data['category_id'])){
|
||||
$map[] = ['source_category_id', '=', $data['category_id']];
|
||||
}
|
||||
|
||||
$result['total_result'] = $this->where($map)->count();
|
||||
if ($result['total_result'] <= 0) {
|
||||
return $result;
|
||||
@@ -101,7 +118,8 @@ class Source extends QfShop
|
||||
}
|
||||
|
||||
$result['items'] = $this->setDefaultOrder($order)
|
||||
->field('source_id as id,title,url,update_time as time,is_time')
|
||||
->field('source_id as id,source_category_id,title,url,update_time as time,is_time')
|
||||
->with('category')
|
||||
->where($map)
|
||||
->withSearch(['page', 'order'], $data)
|
||||
->select()->each(function($item,$key){
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use app\model\QfShop;
|
||||
|
||||
class SourceCategory extends QfShop
|
||||
{
|
||||
/**
|
||||
* 获取列表
|
||||
* @access public
|
||||
* @param array $data 外部数据
|
||||
* @return array|false
|
||||
* @throws
|
||||
*/
|
||||
public function getList(array $data)
|
||||
{
|
||||
|
||||
// 搜索条件
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 0];
|
||||
$result = $this->where($map)->order('sort', 'desc')->select();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>资源分类</title>
|
||||
{include file="common/header"/}
|
||||
<el-form :inline="true">
|
||||
<el-form-item>
|
||||
<el-button icon="el-icon-plus" size="small" @click="clickAdd" plain>添加</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button icon="el-icon-delete" size="small" @click="postMultDelete" plain>批量删除</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table :data="dataList" @selection-change="changeSelection" v-loading="loading">
|
||||
<el-table-column type="selection" width="50">
|
||||
</el-table-column>
|
||||
<el-table-column prop="source_category_id" label="ID" width="60">
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" label="分类名称">
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="80">
|
||||
<template slot-scope="scope">
|
||||
<el-switch v-model="scope.row.status==1?true:false" active-color="#ff4949"
|
||||
@change="clickStatus(scope.row)">
|
||||
</el-switch>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sort" label="排序" width="80">
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-link type="primary" @click="clickEdit(scope.row)" :underline="false">编辑</el-link>
|
||||
<el-link type="danger" @click="clickDelete(scope.row)" :underline="false">删除</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
|
||||
<!-- 添加框 -->
|
||||
<el-dialog title="添加资源分类名称" :visible.sync="dialogFormAdd" width="500px" :modal-append-to-body='false' append-to-body :close-on-click-modal='false'>
|
||||
<el-form :model="formAdd" :rules="rules" ref="formAdd">
|
||||
|
||||
<el-form-item prop="name" label="分类名称" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" v-model="formAdd.name"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="sort" label="排序" :label-width="formLabelWidth">
|
||||
<el-input-number v-model="formAdd.sort" :min="0" :max="999" size="medium" style="width: 120px;"
|
||||
controls-position="right" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="postAdd()">确认添加</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- 修改框 -->
|
||||
<el-dialog title="修改资源分类信息" :visible.sync="dialogFormEdit" width="500px" :modal-append-to-body='false' append-to-body :close-on-click-modal='false'>
|
||||
<el-form :model="formEdit" :rules="rules" ref="formEdit">
|
||||
<el-form-item prop="name" label="分类名称" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" v-model="formEdit.name"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="sort" label="排序" :label-width="formLabelWidth">
|
||||
<el-input-number v-model="formEdit.sort" :min="0" :max="999" size="medium" style="width: 120px;"
|
||||
controls-position="right" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="postEdit()">确认修改</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
{include file="common/footer"/}
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
this.getList();
|
||||
return {
|
||||
formLabelWidth: '80px',
|
||||
dialogFormAdd: false,
|
||||
dialogFormEdit: false,
|
||||
loading: true,
|
||||
dataList: [],
|
||||
selectList: [],
|
||||
formAdd: {
|
||||
sort: 0
|
||||
},
|
||||
formEdit: {
|
||||
},
|
||||
rules: {
|
||||
name: [ { required: true, message: '请输入分类名称', trigger: 'blur' }],
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
postMultDelete() {
|
||||
var that = this;
|
||||
if (that.selectList.length == 0) {
|
||||
that.$message.error('未选择任何分类!');
|
||||
return;
|
||||
}
|
||||
this.$confirm('即将删除选中的分类, 是否确认?', '批量删除', {
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.post('/admin/source_category/delete', Object.assign({}, PostBase, {
|
||||
source_category_id: that.selectList.join(",")
|
||||
}))
|
||||
.then(function (response) {
|
||||
that.getList();
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.$message({
|
||||
message: response.data.message,
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
});
|
||||
}).catch(() => {
|
||||
});
|
||||
},
|
||||
changeSelection(list) {
|
||||
var that = this;
|
||||
that.selectList = [];
|
||||
for (var index in list) {
|
||||
that.selectList.push(list[index].source_category_id);
|
||||
}
|
||||
},
|
||||
postEdit() {
|
||||
var that = this;
|
||||
that.$refs["formEdit"].validate((valid) => {
|
||||
if (valid) {
|
||||
axios.post('/admin/source_category/update', Object.assign({}, PostBase, that.formEdit))
|
||||
.then(function (response) {
|
||||
that.getList();
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.$message({
|
||||
message: response.data.message,
|
||||
type: 'success'
|
||||
});
|
||||
that.dialogFormEdit = false;
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
postAdd() {
|
||||
var that = this;
|
||||
that.$refs['formAdd'].validate((valid) => {
|
||||
if (valid) {
|
||||
axios.post('/admin/source_category/add', Object.assign({}, PostBase, that.formAdd))
|
||||
.then(function (response) {
|
||||
that.getList();
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.$message({
|
||||
message: response.data.message,
|
||||
type: 'success'
|
||||
});
|
||||
that.dialogFormAdd = false;
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
clickAdd() {
|
||||
var that = this;
|
||||
that.formAdd = { sort: 0 };
|
||||
that.dialogFormAdd = true;
|
||||
},
|
||||
clickDelete(row) {
|
||||
var that = this;
|
||||
this.$confirm('即将删除这个分类, 是否确认?', '删除提醒', {
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.post('/admin/source_category/delete', Object.assign({}, PostBase, {
|
||||
source_category_id: row.source_category_id
|
||||
}))
|
||||
.then(function (response) {
|
||||
that.getList();
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.$message({
|
||||
message: response.data.message,
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
}).catch(() => {
|
||||
});
|
||||
},
|
||||
clickStatus(row) {
|
||||
var that = this;
|
||||
axios.post(row.status ? '/admin/source_category/enable' : '/admin/source_category/disable', Object.assign({}, PostBase, {
|
||||
source_category_id: row.source_category_id
|
||||
}))
|
||||
.then(function (response) {
|
||||
that.getList();
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.$message({
|
||||
message: response.data.message,
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
clickEdit(row) {
|
||||
var that = this;
|
||||
that.formEdit = row;
|
||||
axios.post('/admin/source_category/detail', Object.assign({}, PostBase, {
|
||||
source_category_id: row.source_category_id
|
||||
}))
|
||||
.then(function (response) {
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.formEdit = response.data.data;
|
||||
that.dialogFormEdit = true;
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
},
|
||||
getList() {
|
||||
var that = this;
|
||||
that.loading = true;
|
||||
axios.post('/admin/source_category/getList', Object.assign({}, PostBase))
|
||||
.then(function (response) {
|
||||
that.loading = false;
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.dataList = response.data.data;
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.loading = false;
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
</html>
|
||||
@@ -12,6 +12,12 @@
|
||||
<el-button icon="el-icon-document-copy" size="small" @click="getExport" plain>导出资源</el-button>
|
||||
</el-form-item>
|
||||
<div style="float:right">
|
||||
<el-form-item style="width:120px;">
|
||||
<el-select size="small" v-model="search.source_category_id" placeholder="筛选分类">
|
||||
<el-option v-for="item in category" :key="item.source_category_id" :label="item.name" :value="item.source_category_id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-input placeholder="输入关键词搜索" size="small" v-model="search.keyword" @keyup.enter.native="getList_search"></el-input>
|
||||
</el-form-item>
|
||||
@@ -27,11 +33,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="title" label="资源名称">
|
||||
</el-table-column>
|
||||
<el-table-column prop="source_category_id_name" label="资源分类">
|
||||
</el-table-column>
|
||||
<el-table-column prop="url" label="资源地址" align="center">
|
||||
</el-table-column>
|
||||
<el-table-column prop="create_time" label="入库时间" align="center" width="200">
|
||||
<el-table-column prop="is_top" label="置顶" width="90" align="center">
|
||||
<template slot-scope="scope">
|
||||
<p v-if="scope.row.is_top">
|
||||
<el-tag size="mini">置顶</el-tag>
|
||||
</p>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="update_time" label="更新时间" align="center" width="200">
|
||||
<el-table-column prop="sort" label="排序" width="90" align="center">
|
||||
</el-table-column>
|
||||
<el-table-column prop="create_time" label="入库时间" align="center" width="160">
|
||||
</el-table-column>
|
||||
<el-table-column prop="update_time" label="更新时间" align="center" width="160">
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180" align="center">
|
||||
<template slot-scope="scope">
|
||||
@@ -61,12 +78,25 @@
|
||||
<el-dialog title="添加资源" :visible.sync="dialogFormAdd" :modal-append-to-body='false' append-to-body
|
||||
:close-on-click-modal='false' width="680px">
|
||||
<el-form :model="formAdd" :rules="rules" ref="formAdd">
|
||||
<el-form-item prop="source_category_id" label="资源分类" :label-width="formLabelWidth">
|
||||
<el-select size="medium" v-model="formAdd.source_category_id" placeholder="请选择分类">
|
||||
<el-option v-for="item in category" :key="item.source_category_id" :label="item.name" :value="item.source_category_id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="title" label="资源名称" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" placeholder="请输入资源名称" v-model="formAdd.title"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="url" label="资源地址" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" placeholder="请输入资源地址" v-model="formAdd.url"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="sort" label="排序" :label-width="formLabelWidth">
|
||||
<el-input-number v-model="formAdd.sort" :min="0" :max="999" size="medium" style="width: 120px;"
|
||||
controls-position="right" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="is_top" label="置顶" :label-width="formLabelWidth">
|
||||
<el-switch v-model="formAdd.is_top"></el-switch>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="postAdd()">确认添加</el-button>
|
||||
@@ -76,12 +106,26 @@
|
||||
<el-dialog title="修改资源" :visible.sync="dialogFormEdit" :modal-append-to-body='false' append-to-body
|
||||
:close-on-click-modal='false' width="680px">
|
||||
<el-form :model="formEdit" :rules="rules" ref="formEdit">
|
||||
<el-form-item prop="source_category_id" label="资源分类" :label-width="formLabelWidth">
|
||||
<el-select size="medium" v-model="formEdit.source_category_id" placeholder="请选择分类">
|
||||
<el-option v-for="item in category" :key="item.source_category_id" :label="item.name"
|
||||
:value="item.source_category_id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="title" label="资源名称" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" placeholder="请输入资源名称" v-model="formEdit.title"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="url" label="资源地址" :label-width="formLabelWidth">
|
||||
<el-input size="medium" autocomplete="off" placeholder="请输入资源地址" v-model="formEdit.url"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="sort" label="排序" :label-width="formLabelWidth">
|
||||
<el-input-number v-model="formEdit.sort" :min="0" :max="999" size="medium" style="width: 120px;"
|
||||
controls-position="right" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="is_top" label="置顶" :label-width="formLabelWidth">
|
||||
<el-switch v-model="formEdit.is_top"></el-switch>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="postEdit()">确认修改</el-button>
|
||||
@@ -92,7 +136,13 @@
|
||||
<el-dialog title="导入资源" :visible.sync="dialogImport" :modal-append-to-body='false' append-to-body
|
||||
:close-on-click-modal='false' width="600px">
|
||||
<el-form :model="Importform">
|
||||
|
||||
<el-form-item prop="source_category_id" label="资源分类" :label-width="formLabelWidth">
|
||||
<el-select size="medium" v-model="Importform.source_category_id" placeholder="请选择分类">
|
||||
<el-option v-for="item in category" :key="item.source_category_id" :label="item.name"
|
||||
:value="item.source_category_id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="" :label-width="formLabelWidth">
|
||||
<el-upload class="upload-demo" :data="Importform" name="file"
|
||||
ref="ImportUpload"
|
||||
@@ -122,7 +172,8 @@
|
||||
return {
|
||||
search: {
|
||||
keyword: "",
|
||||
filter: "title"
|
||||
filter: "title",
|
||||
source_category_id: ''
|
||||
},
|
||||
formLabelWidth: '120px',
|
||||
dialogFormAdd: false,
|
||||
@@ -146,17 +197,20 @@
|
||||
Importform: {
|
||||
|
||||
},
|
||||
|
||||
category: [],
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
this.getcategory();
|
||||
},
|
||||
methods: {
|
||||
getList_search(val) {
|
||||
if (val == 0) {
|
||||
this.search = {
|
||||
keyword: "",
|
||||
filter: "title"
|
||||
filter: "title",
|
||||
source_category_id: ''
|
||||
}
|
||||
}
|
||||
this.form.page = 1;
|
||||
@@ -253,6 +307,8 @@
|
||||
}))
|
||||
.then(function (response) {
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
response.data.data.source_category_id = response.data.data.source_category_id || undefined
|
||||
response.data.data.is_top = response.data.data.is_top?true:false
|
||||
that.formEdit = response.data.data;
|
||||
that.dialogFormEdit = true;
|
||||
} else {
|
||||
@@ -267,6 +323,24 @@
|
||||
this.form.page = page;
|
||||
this.getList();
|
||||
},
|
||||
getcategory(){
|
||||
var that = this;
|
||||
axios.post('/admin/source_category/getList', Object.assign({}, PostBase))
|
||||
.then(function (response) {
|
||||
that.loading = false;
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.category = response.data.data;
|
||||
that.getList();
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.loading = false;
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
getList() {
|
||||
var that = this;
|
||||
that.loading = true;
|
||||
@@ -275,6 +349,7 @@
|
||||
that.loading = false;
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.dataList = response.data.data;
|
||||
that.setcategory()
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
@@ -284,6 +359,15 @@
|
||||
that.$message.error('服务器内部错误');
|
||||
});
|
||||
},
|
||||
setcategory(){
|
||||
for (let item of this.dataList.data) {
|
||||
for (let items of this.category) {
|
||||
if(item.source_category_id == items.source_category_id){
|
||||
item.source_category_id_name = items.name
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//导入数据
|
||||
ImportShow() {
|
||||
|
||||
Reference in New Issue
Block a user