Browse Source

添加Qs fromData 请求输出格式

master
Eddie 3 years ago
parent
commit
a770d23544
6 changed files with 323 additions and 249 deletions
  1. +3
    -1
      src/api/article.js
  2. +44
    -0
      src/api/sort-management.js
  3. +5
    -2
      src/utils/request.js
  4. +106
    -168
      src/views/sort-management/components/check-books-dialog.vue
  5. +109
    -62
      src/views/sort-management/components/edit-dialog.vue
  6. +56
    -16
      src/views/sort-management/index.vue

+ 3
- 1
src/api/article.js View File

@@ -10,7 +10,9 @@ export function fetchList(query) {
} }


// 文章的编辑、保存 // 文章的编辑、保存
export function editArticle(data) {
export function editArticle(data) {

console.log(data , 'datas')
return request({ return request({
url: '/setCenter/Article/edit', url: '/setCenter/Article/edit',
method: 'post', method: 'post',


+ 44
- 0
src/api/sort-management.js View File

@@ -16,3 +16,47 @@ export function getCategoryList(params) {
}) })
} }




export function getCategoryShow(id, params) {
return request({
url: `category/show/${id}`,
method: 'get',
params: params
})
}



export function getCategoryDelete(id) {
return request({
url: `category/delete/${id}`,
method: 'DELETE'
})
}



export function getCategoryAdd(data) {
console.log(data ,'data')
return request({
url: `category/create`,
method: 'POST',
data: {
name: data.name,
source_platform: data.source_platform
}
})
}



export function getCategoryUpdate( data ,id ) {
console.log(data ,'getCategoryUpdate')

return request({
url: `category/update/${id}`,
method: 'PUT',
data: data
})
}

+ 5
- 2
src/utils/request.js View File

@@ -1,8 +1,9 @@
import axios from 'axios' import axios from 'axios'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'


import qs from 'qs'
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
@@ -19,7 +20,9 @@ service.interceptors.request.use(
config.headers['Content-Type'] = 'application/x-www-form-urlencoded'; config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
config.headers['api-token'] = getToken() || '' config.headers['api-token'] = getToken() || ''


config.data = qs.stringify(config.data) // 转为formdata数据格式
return config return config
}, },
error => { error => {


+ 106
- 168
src/views/sort-management/components/check-books-dialog.vue View File

@@ -2,7 +2,7 @@
<Dialog <Dialog
:is-dialog-exist="isDialog" :is-dialog-exist="isDialog"
:title="dialogTitle" :title="dialogTitle"
:sub-title="dialogSubTitle"
:sub-title="booksItem ? booksItem.btn5Data.name : ''"
:dialog-style="dialogStyle" :dialog-style="dialogStyle"
@close-dialog="handleClose" @close-dialog="handleClose"
> >
@@ -16,224 +16,162 @@
inline inline
> >
<div class="div-main"> <div class="div-main">
<el-form-item
label="书名"
prop="name"
>
<el-input
v-model="formData.name"
placeholder="请输入"
/>
<el-form-item label="书名" prop="name">
<el-input v-model="formData.name" placeholder="请输入" />
</el-form-item> </el-form-item>
<el-form-item
label="分类"
prop="name"
>
<el-input
v-model="formData.name"
placeholder="请输入"
/>
</el-form-item>
<el-form-item
label="简介"
prop="name"
>
<el-input
v-model="formData.name"
placeholder="请输入"
/>

<el-form-item label="简介" prop="book_intro">
<el-input v-model="formData.book_intro" placeholder="请输入" />
</el-form-item> </el-form-item>
</div>
<div class="div-main">
<el-form-item>
<el-button
type="primary"
size="mini"
@click="onSubmit"
>
提交
</el-button>
<el-button
type="info"
plain
size="mini"
@click="resetForm('formData')"
>
<el-form-item label=" ">
<el-button type="primary" size="mini" @click="onSubmit"> 提交 </el-button>
<el-button type="info" plain size="mini" @click="resetForm('formData')">
重置 重置
</el-button> </el-button>
</el-form-item> </el-form-item>
</div> </div>
</el-form> </el-form>
<!-- 操作按钮 -->
<div class="div-btn">
<el-button
type="primary"
icon="el-icon-refresh-right"
size="mini"
@click="_baseRequest(true)"
/>
</div>

<!-- 数据 --> <!-- 数据 -->
<div class="table-container"> <div class="table-container">
<el-table <el-table
v-loading="tableData.length === 0"
:data="tableData" :data="tableData"
border border
fit fit
tooltip-effect="dark" tooltip-effect="dark"
> >
<el-table-column
type="index"
label="序号"
align="center"
width="55"
/>
<el-table-column
label="书名"
align="center"
prop="name"
/>
<el-table-column
label="分类"
align="center"
prop="name"
min-width="100"
/>
<el-table-column
label="书源"
align="center"
prop="name"
min-width="100"
/>
<el-table-column
label="简介"
align="center"
prop="memo"
/>
<el-table-column type="index" label="序号" align="center" width="55" />
<el-table-column label="书名" align="center" prop="book_name" />
<el-table-column label="分类" align="center">
<template slot-scope="scope">{{ booksItem.data.category_name }}</template>
</el-table-column>
<el-table-column label="书源" align="center">
<template slot-scope="scope">{{ booksItem.btn5Data.name }}</template>
</el-table-column>
<el-table-column label="简介" align="center" prop="book_intro" />
</el-table> </el-table>
</div> </div>
<!-- 底部分页组件 -->
<div class="pagination-container">
<el-pagination
:current-page="formData.currentPage"
:page-sizes="[10, 20, 30, 40]"
:page-size="formData.limit"
layout="total, prev, pager, next, sizes,jumper"
:total="formData.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</el-main> </el-main>
</el-container> </el-container>
</Dialog> </Dialog>
</template> </template>


<script> <script>
import Dialog from '@/components/Dialog/index'
import Dialog from "@/components/Dialog/index";


export default { export default {
components: { Dialog }, components: { Dialog },
props: { props: {
isDialog: { isDialog: {
type: Boolean, type: Boolean,
default: false
}
default: false,
},
mod: {
type: Array,
default: () => [],
},
booksItem: {
type: Object,
default: () => {
return {
btn5Data: {
name: "",
},
};
},
},
}, },
watch: {
mod() {
this._baseRequest();
},
},

data() { data() {
return { return {
// dialog样式 // dialog样式
dialogStyle: { dialogStyle: {
'--dialog-width': '1000px',
'--dialog-height': '712px',
'--title-height': '51px'
"--dialog-width": "1000px",
"--dialog-height": "712px",
"--title-height": "51px",
}, },
dialogTitle: '查看书籍',
dialogSubTitle: '笔趣阁',
dialogTitle: "查看书籍",
dialogSubTitle: "笔趣阁",
isSearchVisible: true, isSearchVisible: true,
// 表格数据 // 表格数据
tableData: [
{
name: '11'
}
],
tableData: [],
formData: { formData: {
name: '132456',
// 默认显示页
currentPage: 1,
// 每页页数
limit: 10,
// 总页数
total: 10
}
}
name: "",
book_intro: "",
},
};
}, },
methods: { methods: {
// 基础请求
_baseRequest(refres = false) {
// const params = {
// name: this.formData.name,
// p: this.formData.currentPage,
// limit: this.formData.limit
// }
// filterWordList(params).then(resp => {
// if (parseInt(resp.code) === 0) {
if (refres) {
this.$message.success('刷新成功~')
}
// // console.log(JSON.stringify(resp.data))
// this.tableData = resp.data.list
// this.formData.total = resp.data.total
// }
// })
_baseRequest() {
this.tableData = [];
this.tableData = JSON.parse(JSON.stringify(this.mod));
}, },
// 提交操作
// 提交搜索操作
onSubmit() { onSubmit() {
this._baseRequest()
let data = null;
if (this.formData.name && this.formData.book_intro) {
data = this.mod.filter((item) => {
if (
item.book_name.indexOf(this.formData.name) != -1 &&
item.book_intro.indexOf(this.formData.book_intro) != -1
) {
return item;
}
});
} else if (this.formData.name && !this.formData.book_intro) {
data = this.mod.filter((item) => {
if (item.book_name.indexOf(this.formData.name) != -1) {
return item;
}
});
} else {
data = this.mod.filter((item) => {
if (item.book_intro.indexOf(this.formData.book_intro) != -1) {
return item;
}
});
}
this.tableData = data;
}, },
// 重置操作 // 重置操作
resetForm(val) { resetForm(val) {
this.$refs[val].resetFields()
this._baseRequest()
},
// 每页数据
handleSizeChange(val) {
console.log(`每页 ${val} 条`)
this.formData.limit = val
this._baseRequest()
},
// 当前页
handleCurrentChange(val) {
console.log(`当前页: ${val}`)
this.formData.currentPage = val
this._baseRequest()
this.$refs[val].resetFields();
this._baseRequest();
}, },

handleClose() { handleClose() {
this.$emit('handle-close')
}
}
}
this.$emit("handle-close");
},
},
};
</script> </script>


<style lang="scss" scoped> <style lang="scss" scoped>
.el-container{
.el-container {
width: 100%;
height: 100%;
.el-main {
width: 100%; width: 100%;
height: 100%;
.el-main{
width: 100%;
.div-main{
display: flex;
justify-content: space-between;
flex-flow: row wrap;
padding: 0 5%;
}
.div-btn{
margin-bottom: 10px;
}
.pagination-container{
display: flex;
justify-content: center;
align-items: center;
}
.div-main {
display: flex;
justify-content: space-between;
flex-flow: row wrap;
padding: 0 5%;
}
.div-btn {
margin-bottom: 10px;
}
.pagination-container {
display: flex;
justify-content: center;
align-items: center;
} }
} }
}
</style> </style>

+ 109
- 62
src/views/sort-management/components/edit-dialog.vue View File

@@ -7,110 +7,157 @@
> >
<el-container> <el-container>
<el-main> <el-main>
<el-form
ref="formData"
:model="formData"
label-width="auto"
>
<el-form ref="formData" :model="formData" label-width="auto">
<el-form-item label="书源"> <el-form-item label="书源">
<el-select <el-select
v-model="formData.name"
placeholder="请输入"
v-model="formData.source_platform"
placeholder="请选择"
style="width: 100%" style="width: 100%"
> >
<el-option <el-option
label="区域一"
value="shanghai"
/>
<el-option
label="区域二"
value="beijing"
:label="item.name"
:value="item.value"
v-for="(item, index) in dropdownData"
:key="index"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="分类"> <el-form-item label="分类">
<el-select
v-model="formData.name"
placeholder="请输入"
style="width: 100%"
>
<el-option
label="区域一"
value="shanghai"
/>
<el-option
label="区域二"
value="beijing"
/>
</el-select>
<el-input v-model="formData.name" placeholder="请输入"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-main> </el-main>
<el-footer> <el-footer>
<el-button type="primary">
确认
</el-button>
<el-button @click="handleClose">
取消
</el-button>
<el-button type="primary" @click="onSubmit"> 确认</el-button>
<el-button @click="handleClose"> 取消 </el-button>
</el-footer> </el-footer>
</el-container> </el-container>
</Dialog> </Dialog>
</template> </template>


<script> <script>
import Dialog from '@/components/Dialog/index'
import Dialog from "@/components/Dialog/index";
import { getCategoryAdd, getCategoryUpdate } from "@/api/sort-management";


export default { export default {
components: { Dialog }, components: { Dialog },
props: { props: {
isDialog: { isDialog: {
type: Boolean, type: Boolean,
default: false
default: false,
}, },
// 弹窗标题 // 弹窗标题
dialogTitle: { dialogTitle: {
type: String, type: String,
default: ''
}
default: "",
},
dropdownData: {
type: Array,
default: () => {},
},
selectItem: {
type: Object,
default: () => {
return {
source_platform: "",
name: ""
};
},
},
}, },

watch: {
isDialog(val) {
if (val) {
this.init();
}
},
},

data() { data() {
return { return {
// dialog样式 // dialog样式
dialogStyle: { dialogStyle: {
'--dialog-width': '1000px',
'--dialog-height': '450px',
'--title-height': '51px'
"--dialog-width": "1000px",
"--dialog-height": "450px",
"--title-height": "51px",
}, },
formData: { formData: {
name: '132456'
}
}
source_platform: "",
name: "",
},
};
}, },
methods: { methods: {
init() {
console.log("初始化");
if (this.dialogTitle === "新增分类") {
this.formData = {
source_platform: "",
name: "",
};
} else {
this.formData = this.selectItem;
}
},
handleClose() { handleClose() {
this.$emit('handle-close')
}
}
}
this.$emit("handle-close");
},

onSubmit() {
console.log(this.formData)

if (this.formData.name === "") return this.$message.error("请输入分类名称");
if (this.formData.source_platform === "") return this.$message.error("请选择书源");

if (this.dialogTitle === "新增分类") {
getCategoryAdd({
name: this.formData.name,
source_platform: this.formData.source_platform
}).then((res) => {
this.$emit("handle-success");
this.$message.success('新增成功')
}).catch(err=>{
this.$emit("handle-close");

})
} else {
getCategoryUpdate(
{
name: this.formData.name,
},
this.formData.source_platform
).then((res) => {
this.$emit("handle-success");
this.$message.success('修改成功')
}).catch(err=>{
this.$emit("handle-close");

})
}
},
},
};
</script> </script>


<style lang="scss" scoped> <style lang="scss" scoped>
.el-container{
.el-container {
width: 100%;
height: 100%;
.el-main {
width: 100%;
height: 90%;
padding: 5% 15% 0;
}
.el-footer {
width: 100%; width: 100%;
height: 100%;
.el-main{
width: 100%;
height: 90%;
padding: 5% 15% 0;
}
.el-footer{
width: 100%;
height: 10%;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 5px 10px #000000;
}
height: 10%;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 5px 10px #000000;
} }
}
</style> </style>

+ 56
- 16
src/views/sort-management/index.vue View File

@@ -21,7 +21,7 @@
<el-table-column label="书源" align="center"> <el-table-column label="书源" align="center">
<template slot-scope="scope">{{ btn5Data.name }}</template> <template slot-scope="scope">{{ btn5Data.name }}</template>
</el-table-column> </el-table-column>
<el-table-column label="采集书籍数量" align="center" />
<el-table-column label="采集书籍数量" align="center" prop="count_num" />
<el-table-column prop="address" label="操作" align="center"> <el-table-column prop="address" label="操作" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<CustomButton <CustomButton
@@ -42,13 +42,13 @@
type="danger" type="danger"
icon="delete" icon="delete"
is-svg is-svg
@onClick="handleDelete(scope.$index)"
@onClick="handleDelete(scope.row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>


<el-footer>
<!-- <el-footer>
<el-pagination <el-pagination
:current-page="currentPage" :current-page="currentPage"
:page-sizes="[5, 10, 15, 20, 30]" :page-sizes="[5, 10, 15, 20, 30]"
@@ -58,7 +58,7 @@
@size-change="handleSizeChange" @size-change="handleSizeChange"
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
/> />
</el-footer>
</el-footer> -->
</div> </div>
</el-main> </el-main>
<!-- 编辑、新增弹窗--> <!-- 编辑、新增弹窗-->
@@ -66,11 +66,18 @@
:is-dialog="isEditDialog" :is-dialog="isEditDialog"
:dialog-title="editTitleDialog" :dialog-title="editTitleDialog"
@handle-close="isEditDialog = false" @handle-close="isEditDialog = false"
:btn5Data="btn5Data"
:dropdownData="dropdownData"
:CategoryList="CategoryList" :CategoryList="CategoryList"
:selectItem="selectItem"
@handle-success="onHandleSuccess"
/> />
<!-- 查看书籍弹窗--> <!-- 查看书籍弹窗-->
<CheckBooksDialog :is-dialog="isCheckDialog" @handle-close="isCheckDialog = false" />
<CheckBooksDialog
:mod="booksData"
:booksItem="booksItem"
:is-dialog="isCheckDialog"
@handle-close="isCheckDialog = false"
/>
</el-container> </el-container>
</template> </template>


@@ -80,7 +87,12 @@ import CustomButton from "@/components/CustomButton/index";
import EditDialog from "./components/edit-dialog"; import EditDialog from "./components/edit-dialog";
import CheckBooksDialog from "./components/check-books-dialog"; import CheckBooksDialog from "./components/check-books-dialog";


import { getPlatformList, getCategoryList } from "@/api/sort-management";
import {
getPlatformList,
getCategoryList,
getCategoryShow,
getCategoryDelete,
} from "@/api/sort-management";


export default { export default {
components: { components: {
@@ -103,17 +115,25 @@ export default {
dropdownData: [], dropdownData: [],
CategoryList: [], CategoryList: [],
btn5Data: {}, btn5Data: {},
booksData: null,
booksItem: null,
selectItem: {},
}; };
}, },
created() { created() {
this.init(); this.init();
}, },
methods: { methods: {
init() {
this.onPlatformList();
init(refresh = false) {
this.onPlatformList(refresh);
},

onHandleSuccess() {
this.init();
this.isEditDialog = false;
}, },


onPlatformList() {
onPlatformList(refresh) {
getPlatformList().then((res) => { getPlatformList().then((res) => {
let obj = res.data; let obj = res.data;
let arr = []; let arr = [];
@@ -128,39 +148,56 @@ export default {
this.dropdownData = arr; this.dropdownData = arr;
this.btn5Data = arr[0]; this.btn5Data = arr[0];
this.onCategoryList(arr[0].value); this.onCategoryList(arr[0].value);
refresh && this.$message.success("刷新成功");
}); });
}, },


onCategoryList(source_platform) { onCategoryList(source_platform) {
getCategoryList({ getCategoryList({
source_platform,
source_platform: source_platform,
need_num: true,
}).then((res) => { }).then((res) => {
this.tableData = res.data; // 分类列表 this.tableData = res.data; // 分类列表
}); });
}, },


handleButton5(data) { handleButton5(data) {
console.log(data)
this.btn5Data = data; this.btn5Data = data;
this.onCategoryList(data.value);
this.onCategoryList(data.value);


this.$forceUpdate(); this.$forceUpdate();
}, },


refreshData() { refreshData() {
console.log("刷新");
this.init(true);
}, },
// 打开编辑弹窗操作 // 打开编辑弹窗操作
openEditDialog(row) { openEditDialog(row) {
this.isEditDialog = true; this.isEditDialog = true;
if (row) { if (row) {
this.editTitleDialog = "编辑分类"; this.editTitleDialog = "编辑分类";
this.selectItem = {
source_platform: row.id,
name: row.category_name,
};
} else { } else {
this.editTitleDialog = "新增分类"; this.editTitleDialog = "新增分类";
} }
}, },
// 打开查看书籍弹窗 // 打开查看书籍弹窗
openCheckBooksDialog() {
openCheckBooksDialog(data) {
this.booksData = [];
getCategoryShow(data.id, {
source_platform: this.btn5Data.value,
}).then((res) => {
this.booksData = res.data;
this.booksItem = {
data: data,
btn5Data: this.btn5Data,
};
});

this.isCheckDialog = true; this.isCheckDialog = true;
}, },


@@ -175,7 +212,10 @@ export default {
} }
) )
.then(() => { .then(() => {
this.selectItem = row;
console.log(row);
getCategoryDelete(row.id).then((res) => {
this.init();
});
}) })
.catch(() => {}); .catch(() => {});
}, },


Loading…
Cancel
Save