1.接口文档
2.配置会员服务路由
在gulimall-gateway中配置会员服务的路由
#会员服务- id: member_routeuri: lb://gulimall-memberpredicates:- Path=/api/member/**filters:- RewritePath=/api/(?<segment>.*),/$\{segment}
3.前端完整代码
3.1.level.vue
<template><div class="mod-config"><el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()"><el-form-item><el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input></el-form-item><el-form-item><el-button @click="getDataList()">查询</el-button><el-buttonv-if="isAuth('member:memberlevel:save')"type="primary"@click="addOrUpdateHandle()">新增</el-button><el-buttonv-if="isAuth('member:memberlevel:delete')"type="danger"@click="deleteHandle()":disabled="dataListSelections.length <= 0">批量删除</el-button></el-form-item></el-form><el-table:data="dataList"borderv-loading="dataListLoading"@selection-change="selectionChangeHandle"style="width: 100%;"><el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column><el-table-column prop="id" header-align="center" align="center" label="id"></el-table-column><el-table-column prop="name" header-align="center" align="center" label="等级名称"></el-table-column><el-table-column prop="growthPoint" header-align="center" align="center" label="所需成长值"></el-table-column><el-table-column prop="defaultStatus" header-align="center" align="center" label="默认等级"><template slot-scope="scope"><i class="el-icon-success" v-if="scope.row.defaultStatus==1"></i><i class="el-icon-error" v-else></i></template></el-table-column><el-table-column prop="freeFreightPoint" header-align="center" align="center" label="免运费标准"></el-table-column><el-table-columnprop="commentGrowthPoint"header-align="center"align="center"label="每次评价获取的成长值"></el-table-column><el-table-column label="特权"header-align="center" align="center" ><el-table-columnprop="priviledgeFreeFreight"header-align="center"align="center"label="免邮特权"><template slot-scope="scope"><i class="el-icon-success" v-if="scope.row.priviledgeFreeFreight==1"></i><i class="el-icon-error" v-else></i></template></el-table-column><el-table-columnprop="priviledgeMemberPrice"header-align="center"align="center"label="会员价格特权"width="120px"><template slot-scope="scope"><i class="el-icon-success" v-if="scope.row.priviledgeMemberPrice==1"></i><i class="el-icon-error" v-else></i></template></el-table-column><el-table-columnprop="priviledgeBirthday"header-align="center"align="center"label="生日特权"><template slot-scope="scope"><i class="el-icon-success" v-if="scope.row.priviledgeBirthday==1"></i><i class="el-icon-error" v-else></i></template></el-table-column></el-table-column><el-table-column prop="note" header-align="center" align="center" label="备注"></el-table-column><el-table-column fixed="right" header-align="center" align="center" width="150" label="操作"><template slot-scope="scope"><el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button><el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button></template></el-table-column></el-table><el-pagination@size-change="sizeChangeHandle"@current-change="currentChangeHandle":current-page="pageIndex":page-sizes="[10, 20, 50, 100]":page-size="pageSize":total="totalPage"layout="total, sizes, prev, pager, next, jumper"></el-pagination><!-- 弹窗, 新增 / 修改 --><add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update></div>
</template><script>
import AddOrUpdate from "./memberlevel-add-or-update";
export default {data() {return {dataForm: {key: ""},dataList: [],pageIndex: 1,pageSize: 10,totalPage: 0,dataListLoading: false,dataListSelections: [],addOrUpdateVisible: false};},components: {AddOrUpdate},activated() {this.getDataList();},methods: {// 获取数据列表getDataList() {this.dataListLoading = true;this.$http({url: this.$http.adornUrl("/member/memberlevel/list"),method: "get",params: this.$http.adornParams({page: this.pageIndex,limit: this.pageSize,key: this.dataForm.key})}).then(({ data }) => {if (data && data.code === 0) {this.dataList = data.page.list;this.totalPage = data.page.totalCount;} else {this.dataList = [];this.totalPage = 0;}this.dataListLoading = false;});},// 每页数sizeChangeHandle(val) {this.pageSize = val;this.pageIndex = 1;this.getDataList();},// 当前页currentChangeHandle(val) {this.pageIndex = val;this.getDataList();},// 多选selectionChangeHandle(val) {this.dataListSelections = val;},// 新增 / 修改addOrUpdateHandle(id) {this.addOrUpdateVisible = true;this.$nextTick(() => {this.$refs.addOrUpdate.init(id);});},// 删除deleteHandle(id) {var ids = id? [id]: this.dataListSelections.map(item => {return item.id;});this.$confirm(`确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,"提示",{confirmButtonText: "确定",cancelButtonText: "取消",type: "warning"}).then(() => {this.$http({url: this.$http.adornUrl("/member/memberlevel/delete"),method: "post",data: this.$http.adornData(ids, false)}).then(({ data }) => {if (data && data.code === 0) {this.$message({message: "操作成功",type: "success",duration: 1500,onClose: () => {this.getDataList();}});} else {this.$message.error(data.msg);}});});}}
};
</script>
3.2.memberlevel-add-or-update.vue
<template><el-dialog:title="!dataForm.id ? '新增' : '修改'":close-on-click-modal="false":visible.sync="visible"><el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px"><el-form-item label="等级名称" prop="name"><el-input v-model="dataForm.name" placeholder="等级名称"></el-input></el-form-item><el-form-item label="所需成长值" prop="growthPoint"><el-input-number v-model="dataForm.growthPoint" :min="0"></el-input-number></el-form-item><el-form-item label="默认等级" prop="defaultStatus"><el-checkbox v-model="dataForm.defaultStatus" :true-label="1" :false-label="0"></el-checkbox></el-form-item><el-form-item label="免运费标准" prop="freeFreightPoint"><el-input-number :min="0" v-model="dataForm.freeFreightPoint"></el-input-number></el-form-item><el-form-item label="每次评价获取的成长值" prop="commentGrowthPoint" label-width="180px"><el-input-number :min="0" v-model="dataForm.commentGrowthPoint"></el-input-number></el-form-item><el-form-item label="是否有免邮特权" prop="priviledgeFreeFreight"><el-checkbox v-model="dataForm.priviledgeFreeFreight" :true-label="1" :false-label="0"></el-checkbox></el-form-item><el-form-item label="是否有会员价格特权" prop="priviledgeMemberPrice" label-width="160px"><el-checkbox v-model="dataForm.priviledgeMemberPrice" :true-label="1" :false-label="0"></el-checkbox></el-form-item><el-form-item label="是否有生日特权" prop="priviledgeBirthday"><el-checkbox v-model="dataForm.priviledgeBirthday" :true-label="1" :false-label="0"></el-checkbox></el-form-item><el-form-item label="备注" prop="note"><el-input v-model="dataForm.note" placeholder="备注"></el-input></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="visible = false">取消</el-button><el-button type="primary" @click="dataFormSubmit()">确定</el-button></span></el-dialog>
</template><script>export default {data () {return {visible: false,dataForm: {id: 0,name: '',growthPoint: 0,defaultStatus: 0,freeFreightPoint: 0,commentGrowthPoint: 0,priviledgeFreeFreight: 0,priviledgeMemberPrice: 0,priviledgeBirthday: 0,note: ""},dataRule: {name: [{ required: true, message: '等级名称不能为空', trigger: 'blur' }],growthPoint: [{ required: true, message: '等级需要的成长值不能为空', trigger: 'blur' }],defaultStatus: [{ required: true, message: '是否为默认等级[0->不是;1->是]不能为空', trigger: 'blur' }],freeFreightPoint: [{ required: true, message: '免运费标准不能为空', trigger: 'blur' }],commentGrowthPoint: [{ required: true, message: '每次评价获取的成长值不能为空', trigger: 'blur' }],priviledgeFreeFreight: [{ required: true, message: '是否有免邮特权不能为空', trigger: 'blur' }],priviledgeMemberPrice: [{ required: true, message: '是否有会员价格特权不能为空', trigger: 'blur' }],priviledgeBirthday: [{ required: true, message: '是否有生日特权不能为空', trigger: 'blur' }],note: [{ required: true, message: '备注不能为空', trigger: 'blur' }]}}},methods: {init (id) {this.dataForm.id = id || 0this.visible = truethis.$nextTick(() => {this.$refs['dataForm'].resetFields()if (this.dataForm.id) {this.$http({url: this.$http.adornUrl(`/member/memberlevel/info/${this.dataForm.id}`),method: 'get',params: this.$http.adornParams()}).then(({data}) => {if (data && data.code === 0) {this.dataForm.name = data.memberLevel.namethis.dataForm.growthPoint = data.memberLevel.growthPoint||0this.dataForm.defaultStatus = data.memberLevel.defaultStatus||0this.dataForm.freeFreightPoint = data.memberLevel.freeFreightPoint||0this.dataForm.commentGrowthPoint = data.memberLevel.commentGrowthPoint||0this.dataForm.priviledgeFreeFreight = data.memberLevel.priviledgeFreeFreight||0this.dataForm.priviledgeMemberPrice = data.memberLevel.priviledgeMemberPrice||0this.dataForm.priviledgeBirthday = data.memberLevel.priviledgeBirthday||0this.dataForm.note = data.memberLevel.note}})}})},// 表单提交dataFormSubmit () {this.$refs['dataForm'].validate((valid) => {if (valid) {this.$http({url: this.$http.adornUrl(`/member/memberlevel/${!this.dataForm.id ? 'save' : 'update'}`),method: 'post',data: this.$http.adornData({'id': this.dataForm.id || undefined,'name': this.dataForm.name,'growthPoint': this.dataForm.growthPoint,'defaultStatus': this.dataForm.defaultStatus,'freeFreightPoint': this.dataForm.freeFreightPoint,'commentGrowthPoint': this.dataForm.commentGrowthPoint,'priviledgeFreeFreight': this.dataForm.priviledgeFreeFreight,'priviledgeMemberPrice': this.dataForm.priviledgeMemberPrice,'priviledgeBirthday': this.dataForm.priviledgeBirthday,'note': this.dataForm.note})}).then(({data}) => {if (data && data.code === 0) {this.$message({message: '操作成功',type: 'success',duration: 1500,onClose: () => {this.visible = falsethis.$emit('refreshDataList')}})} else {this.$message.error(data.msg)}})}})}}}
</script>