梦学谷项目(下)
Posted 李耀书
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了梦学谷项目(下)相关的知识,希望对你有一定的参考价值。
梦学谷项目(下)
接上一篇的技术点分析,在整体项目汇中,由于在之前的项目中对mock.js
假数据从未有过了解,所以对假数据的使用做出了总结。
第一步:
登录假数据平台:https://www.fastmock.site/#/,完成注册。
第二步:
创建新项目,设置项目的基准路径
第三步:
设置假数据,
设置假数据时,要注意的是请求数据时的数据路径也是需要进行设置的。
设置假的数据,在做项目的过程中,是为了方便在后端小伙伴还未完成接口的时候,方便我们能够提前的搭好框架。
小结:
通过对
axios
的封装,能够方便我们日后对代码的维护。减少工作量。假数据的使用:可以很大程度的提高我们的工作进度
等这些准备工作都做完后,我们就可以进入我们的项目中进行逻辑的梳理。
纵观整个项目,其实技术点的体现并不明显,我们通过对axios
的封装,以及mock.js
假数据的使用,已经对整体项目的技术点已经有了体现,下面我通过会员管理
模块的业务逻辑的梳理,对整个项目的技术点作出一个大概的总结。
首先:是对于api
的封装
import request from '../utils/index'
export default {
list(page, size) {
return request({
url: `/userList/${page}/${size}`,
method: 'get',
})
},
add(addForm) {
return request({
url: `/mearge`,
method: 'post',
data: addForm,
})
},
del(id) {
return request({
url: `/del/${id}`,
method: 'delete'
})
},
edit(id, editForm) {
return request({
url: `/edit/${id}`,
method: 'put',
data: editForm
})
}
}
<template>
<div id="replace">
<Bread />
<!-- 查询栏 -->
<el-row>
<el-form
:inline="true"
:model="formInline"
ref="formRef"
class="demo-form-inline addForm"
>
<el-form-item>
<el-input
v-model="formInline.cardNum"
placeholder="会员卡号"
></el-input>
</el-form-item>
<el-form-item>
<el-input v-model="formInline.name" placeholder="会员名字"></el-input>
</el-form-item>
<el-form-item>
<el-select v-model="formInline.payType" placeholder="支付类型">
<el-option
:label="item.label"
:value="item.value"
v-for="item in opation"
:key="item.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-date-picker
type="date"
placeholder="选择日期"
v-model="formInline.birthday"
style="width: 100%"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="inquire">查询</el-button>
<el-button type="primary" @click="add">新增</el-button>
<el-button type="primary" @click="rest">重置</el-button>
</el-form-item>
</el-form>
</el-row>
<!-- 表格区域 -->
<el-table :data="tableData" border>
<el-table-column type="index" label="序号"> </el-table-column>
<el-table-column prop="cardNum" label="会员卡号"> </el-table-column>
<el-table-column prop="name" label="会员姓名"> </el-table-column>
<el-table-column prop="birthday" label="会员生日"> </el-table-column>
<el-table-column prop="phone" label="手机号码"> </el-table-column>
<el-table-column prop="integral" label="可用积分"> </el-table-column>
<el-table-column prop="money" label="开卡金额"> </el-table-column>
<el-table-column prop="payType" label="支付类型">
<template v-slot="scope">
<span v-if="scope.row.payType == 1">微信</span>
<span v-if="scope.row.payType == 2">银行卡</span>
<span v-if="scope.row.payType == 3">支付宝</span>
<span v-if="scope.row.payType == 4">现金</span>
</template>
</el-table-column>
<el-table-column prop="address" label="会员地址"> </el-table-column>
<el-table-column label="操作">
<!-- 操作区域 -->
<template v-slot="scope">
<el-button
size="mini"
class="el-icon-delete"
@click="del(scope.row)"
></el-button>
<el-button
type="danger"
size="mini"
class="el-icon-edit"
@click="edit(scope)"
></el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页器 -->
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="queryInfo.pagenum"
:page-sizes="[3, 6, 12, 18]"
:page-size="queryInfo.pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
>
</el-pagination>
<!-- 新增数据对话框 -->
<el-dialog
:title="titleText + '用户'"
:visible.sync="addDialogVisible"
width="30%"
>
<!-- 新增form表单 -->
<el-form
:model="addForm"
:rules="addRules"
label-width="80px"
ref="addRef"
>
<el-form-item label="会员卡号" prop="cardNum">
<el-input v-model="addForm.cardNum"></el-input>
</el-form-item>
<el-form-item label="会员姓名" prop="name">
<el-input v-model="addForm.name"></el-input>
</el-form-item>
<el-form-item label="会员生日">
<el-date-picker
type="date"
placeholder="会员生日"
v-model="addForm.birthday"
style="width: 100%"
></el-date-picker>
</el-form-item>
<el-form-item label="手机号码">
<el-input v-model="addForm.phone"></el-input>
</el-form-item>
<el-form-item label="开卡金额">
<el-input v-model="addForm.money"></el-input>
</el-form-item>
<el-form-item label="可用积分">
<el-input v-model="addForm.integral"></el-input>
</el-form-item>
<el-form-item prop="payType" label="支付类型">
<el-select v-model="addForm.payType" placeholder="支付类型">
<el-option
:label="item.label"
:value="item.value"
v-for="item in opation"
:key="item.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="会员地址">
<el-input type="textarea" v-model="addForm.address"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="addDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="addDialog">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import Bread from "./bread";
import userApi from "../api/Users";
export default {
components: {
Bread,
},
data() {
return {
addDialogVisible: false, //添加对话框初始状态
addForm: {
id: null,
cardNum: "",
name: "",
birthday: "",
phone: "",
money: 0,
integral: 0,
payType: "",
address: "",
},
formInline: {},
flag: false,
// 多选数据
opation: [
{ value: 1, label: "微信" },
{ value: 2, label: "现金" },
{ value: 3, label: "支付宝" },
{ value: 4, label: "银行卡" },
],
queryInfo: {
query: "",
pagesize: 5,
pagenum: 10,
},
tableData: [],
total: 0,
// 校验规则
addRules: {
cardNum: [
{ required: true, message: "请输入会员卡号", trigger: "blur" },
],
name: [{ required: true, message: "请输入会员姓名", trigger: "blur" }],
payType: [
{ required: true, message: "请选择付款方式", trigger: "blur" },
],
},
};
},
created() {
this.getList();
// console.log(this.titleText);
},
methods: {
inquire() {
this.$refs.formRef.validate((valid) => {
if (!valid) return;
this.getList();
});
},
// 新增
add() {
this.flag = true;
this.addDialogVisible = true;
this.addForm.id = "";
this.addForm.cardNum = "";
this.addForm.name = "";
this.addForm.birthday = "";
this.addForm.phone = "";
this.addForm.money = 0;
this.addForm.integral = 0;
this.addForm.payType = "";
this.addForm.address = "";
},
async addDialog() {
if (this.flag) {
console.log(this.addForm);
const { data: res } = await userApi.add(this.addForm);
if (res.code !== 2000) {
this.$message.error("添加用户失败");
}
this.$message.success("添加用户成功");
} else {
const { data: res } = await userApi.edit(this.addForm.id, this.addForm);
if (res.code !== 2000) {
this.$message.error(res.message);
} else {
this.$message.success(res.message);
}
}
this.addDialogVisible = false;
this.getList();
},
// 获取所有数据
async getList() {
const { data: res } = await userApi.list(
this.queryInfo.pagenum,
this.queryInfo.pagesize
);
console.log(res);
this.tableData = res.data.rows;
this.total = this.tableData.length;
},
// 点击进行删除
async del(id) {
const confirmText = await this.$confirm(
"此操作将永久删除该文件, 是否继续?",
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
).catch((err) => err);
if (confirmText !== "confirm") {
return this.$message.info("已取消删除");
}
const { data: res } = await userApi.del(id);
if (res.code !== 2000) {
this.$message.error("删除会员失败")梦学谷项目(上)