vue+element ui+腾讯云开发打造会员管理系统之实战教程(六)类别管理
2023-09-14 09:13:53 时间
需求分析
日常人们在管理数据的时候,往往会进行分类管理,数据分类一个是便于记忆,另一个也便于检索,尤其商超的业务,产品可能多达几千种,但是收营员在结账的时候可以通过切换类别来快速的搜索商品,所以有了此模块的构思,功能比较简单,只需要能够维护类别名称即可,包括通常的增删改查操作。
列表
新增
功能设计
路由
{
path: '/category',
component: Layout,
children: [{
path: 'index',
name: 'category',
component: () => import('@/views/category/index'),
meta: { title: '类别管理', icon: 'category' }
}]
}
注册页面
页面代码
<template>
<div class="app-container">
<div class="filter-container">
<el-input v-model="listQuery.name" placeholder="名称" style="width: 200px;margin-right:5px" class="filter-item" clearable @keyup.enter.native="handleFilter" />
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
查询
</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
新增
</el-button>
<el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
导出
</el-button>
</div>
<el-table
v-loading="listLoading"
:data="list"
element-loading-text="Loading"
border
fit
highlight-current-row
>
<el-table-column align="center" label="序号" width="95">
<template slot-scope="scope">
{{ scope.$index+1 }}
</template>
</el-table-column>
<el-table-column v-if="show" label="ID" prop="_id" align="center" width="80">
<template slot-scope="{row}">
<span>{{ row._id }}</span>
</template>
</el-table-column>
<el-table-column label="类别名称">
<template slot-scope="scope">
{{ scope.row.name }}
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
<template slot-scope="{row,$index}">
<el-button type="primary" icon="el-icon-edit" size="mini" @click="handleUpdate(row)">
编辑
</el-button>
<el-button v-if="row.status!='deleted'" icon="el-icon-delete" size="mini" type="danger" @click="handleDelete(row,$index)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
<el-form-item v-if="show" label="ID" prop="_id">
<el-input v-model="temp._id" />
</el-form-item>
<el-form-item label="类别名称" prop="name" label-width="80px">
<el-input v-model="temp.name" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">
取消
</el-button>
<el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
保存
</el-button>
</div>
</el-dialog>
<el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
<el-table :data="pvData" border fit highlight-current-row style="width: 100%">
<el-table-column prop="key" label="Channel" />
<el-table-column prop="pv" label="Pv" />
</el-table>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogPvVisible = false">Confirm</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
// import { getList } from '@/api/customer'
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination'
import { parseTime } from '@/utils'
export default {
filters: {
statusFilter(status) {
const statusMap = {
published: 'success',
draft: 'gray',
deleted: 'danger'
}
return statusMap[status]
}
},
components: { Pagination },
directives: { waves },
data() {
return {
list: null,
listLoading: true,
show: false,
total: 0,
listQuery: {
page: 1,
limit: 10,
name: undefined,
telphone: undefined
},
temp: {
_id: undefined,
name: ''
},
dialogStatus: '',
textMap: {
update: '编辑类别',
create: '新增类别'
},
dialogPvVisible: false,
pvData: [],
rules: {
name: [{ required: true, message: '名称必须填写', trigger: 'blur' }]
},
dialogFormVisible: false,
downloadLoading: false
}
},
async created() {
// const username = this.$store.state.user.username
// const password = this.$store.state.user.password
const loginState = this.$cloudbase.auth().hasLoginState()
if (loginState) {
// 登录态有效
this.fetchData()
} else {
// 没有登录态,或者登录态已经失效
console.log('未登录')
await this.$store.dispatch('user/logout')
this.$cloudbase.auth({ persistence: 'local' }).signOut()
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
}
// this.$cloudbase.auth({ persistence: 'local' }).signInWithEmailAndPassword(username, password)
},
methods: {
async fetchData() {
this.listLoading = true
console.log(this.listQuery.page)
console.log(this.listQuery.limit)
const queryString = {}
if (this.listQuery.name) {
queryString.name = this.listQuery.name
}
const queryResult = await this.$cloudbase.database().collection('category').where(queryString).skip((this.listQuery.page - 1) * this.listQuery.limit).limit(this.listQuery.limit).orderBy('createdate', 'desc').get()
const queryTotal = await this.$cloudbase.database().collection('category').where(queryString).count()
this.list = queryResult.data
this.listLoading = false
console.log(queryTotal)
this.total = queryTotal.total
console.log(this.list)
/* getList().then(response => {
this.list = response.data.items
this.listLoading = false
})*/
},
resetTemp() {
this.temp = {
_id: undefined,
name: ''
}
},
handleCreate() {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.$cloudbase.database().collection('category').add({
name: this.temp.name,
createdate: new Date()
}).then((res) => {
this.list.unshift(this.temp)
this.dialogFormVisible = false
this.$notify({
title: '提示信息',
message: '新增成功',
type: 'success',
duration: 2000
})
this.fetchData()
}).catch((e) => {})
}
})
},
handleFilter() {
this.fetchData()
},
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['类别名称']
const filterVal = ['name']
const data = this.formatJson(filterVal)
excel.export_json_to_excel({
header: tHeader,
data,
filename: '类别表'
})
this.downloadLoading = false
})
},
formatJson(filterVal) {
return this.list.map(v => filterVal.map(j => {
if (j === 'timestamp') {
return parseTime(v[j])
} else {
return v[j]
}
}))
},
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const tempData = Object.assign({}, this.temp)
tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
console.log(this.dialogFormVisible)
this.$cloudbase.database().collection('category').doc(this.temp._id)
.update({
name: this.temp.name
}).then(res => {
const index = this.list.findIndex(v => v._id === this.temp._id)
this.list.splice(index, 1, this.temp)
this.dialogFormVisible = false
this.$notify({
title: '操作提示',
message: '更新成功',
type: 'success',
duration: 2000
})
})
}
})
},
handleUpdate(row) {
console.log(row)
this.temp = Object.assign({}, row) // copy obj
this.temp.timestamp = new Date(this.temp.timestamp)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
async handleDelete(row, index) {
await this.$cloudbase.database().collection('category').doc(row._id).remove()
this.$notify({
title: '操作提示',
message: '删除成功',
type: 'success',
duration: 2000
})
this.listQuery.name = undefined
this.fetchData()
}
}
}
</script>
<style scoped>
.filter-container{
padding-bottom:10px
}
</style>
源码
源码请访问
https://gitee.com/tuodagitee/membercms.git
相关文章
- Vue中显示img图片,显示不出来怎么办?vue显示图片
- Vue数据可视化组件:data-view
- vscode引入vue_vscode配置vue开发环境
- Vue笔记(11) vue-router
- Vue3开发实战02-vue项目添加状态管理Vuex,路由router,以及http请求a
- vue怎么使用layui_layui动态添加输入框
- 一篇把vue准备工作说的明明白白的(奶妈级教程)
- 基于SpringBoot+Redis+Vue的后台管理系统开源项目,附源码地址
- VUE 数据分页
- vue源码分析-挂载流程和模板编译
- Vue响应式系统原理并实现一个双向绑定
- 你知道import Vue from 'vue' 吗?
- 最新版后台前端管理系统框架: vue-admin-work-p
- 一起吹过的晚风就算相拥 — Vue Admin Work 与 Pinia的邂逅相拥---Pinia实战篇
- Vue(五)计算属性、过滤器、axios、vue 生命周期
- vue3 报错解决:找不到模块‘xxx.vue’或其相应的类型声明。(Vue 3 can not find module)
- Vue全家桶介绍_vue全家桶有什么好处
- Vue的异步更新实现原理是怎样的?
- Vue的computed和watch的区别是什么
- 一个Vue表单的终极解决方案
- 基于Vue+SSM+SpringCloudAlibaba的科目课程管理系统
- IDEA安装Vue插件后为什么创建.vue文件不显示vue图标
- 开心档-软件开发入门之Vue.js Ajax(vue-resource)
- Vue.js 与MySQL结合,打造高效Web应用程序(vue.js mysql)
- 用Vue从Redis中获取强有力的数据(vue用redis中数据)
- Vue如何连接Redis数据库(vue怎么连接Redis)
- Vue应用中部署Redis(vue中使用redis)
- Vue搭配Redis做针对性取值(vue redis取值)