前端学习(2028)vue之电商管理系统电商系统之展示物流进度
生活随笔
收集整理的這篇文章主要介紹了
前端学习(2028)vue之电商管理系统电商系统之展示物流进度
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
目錄結(jié)構(gòu)
router.js
import Vue from 'vue' import Router from 'vue-router' import Login from './components/Login.vue' import Home from './components/Home.vue' import Welcome from './components/Welcome.vue' import Users from './components/user/Users.vue' import Right from './components/power/Right.vue' import Roles from './components/power/Roles.vue' import Cate from './components/goods/Cate.vue' import Params from './components/goods/Params.vue' import List from './components/goods/List.vue' import Add from './components/goods/Add.vue' import Order from './components/order/Order.vue' Vue.use(Router)const router = new Router({routes: [{path: '/',redirect: '/login'},{path: '/login',component: Login},{path: '/home',component: Home,redirect: '/welcome',children: [{path: '/welcome',component: Welcome}, {path: '/users',component: Users},{path: '/rights',component: Right},{path: '/roles',component: Roles},{path: '/categories',component: Cate}, {path: '/params',component: Params}, {path: '/goods',component: List},{path: '/goods/add',component: Add},{path: '/orders',component: Order}]}] }); //掛載路由導(dǎo)航守衛(wèi) router.beforeEach((to, from, next) => {if (to.path === '/login') return next();//獲取tokenconst tokenStr = window.sessionStorage.getItem('token')if (!tokenStr) return next('/login')next(); })export default routerlogin.vue
<template><div class="login_container"><div class="login_box"><div class="avatar_box"><img src="../assets/logo.png"></div><!-- 表單區(qū)域--><el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form"><!-- 登錄區(qū)域--><el-form-item prop="username"><el-input v-model="loginForm.username" prefix-icon="iconfont icon-user"></el-input></el-form-item><el-form-item prop="password"><el-input type="password" v-model="loginForm.password" prefix-icon="iconfont icon-3702mima"></el-input></el-form-item><el-form-item class="btns"><el-button type="primary" @click="login">登錄</el-button><el-button type="info" @click="resetLoginForm">重置</el-button></el-form-item></el-form></div> </div></template><script> export default{data(){return{//這是登錄表單的數(shù)據(jù)loginForm:{username:'geyao',password:'12345678'},// 表單驗(yàn)證loginFormRules: {username: [{ required: true, message: '請(qǐng)輸入用戶(hù)名', trigger: 'blur' },{ min: 2, max: 10, message: '長(zhǎng)度在 2 到 10 個(gè)字符', trigger: 'blur' }],password: [{ required: true, message: '請(qǐng)輸入用戶(hù)密碼', trigger: 'blur' },{ min: 6, max: 18, message: '長(zhǎng)度在 6 到 18 個(gè)字符', trigger: 'blur' }]}}},methods:{resetLoginForm(){// console.log(this)this.$refs.loginFormRef.resetFields();},login(){this.$refs.loginFormRef.validate(async valid =>{if(!valid) return;const {data:res}=await this.$http.post('login',this.loginForm);if(res.meta.status!==200) return this.$message.error('登錄失敗');this.$message.success('登錄成功');// 1、將登陸成功之后的token, 保存到客戶(hù)端的sessionStorage中; // 1.1 項(xiàng)目中出現(xiàn)了登錄之外的其他API接口,必須在登陸之后才能訪問(wèn)// 1.2 token 只應(yīng)在當(dāng)前網(wǎng)站打開(kāi)期間生效,所以將token保存在window.sessionStorage.setItem('token', res.data.token)// 2、通過(guò)編程式導(dǎo)航跳轉(zhuǎn)到后臺(tái)主頁(yè), 路由地址為:/homethis.$router.push('/home')});}} } </script><style lang="less" scoped> .login_container {background-color: #2b4b6b;height: 100%; } .login_box {width: 450px;height: 360px;background-color: #fff;border-radius: 3px;position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);background-color: #fff; }.avatar_box {width: 130px;height: 130px;border: 1px solid #eee;border-radius: 50%;padding: 10px;box-shadow: 0 0 10px #ddd;position: absolute;left: 50%;transform: translate(-50%, -50%);background-color: #fff;img {width: 100%;height: 100%;border-radius: 50%;background-color: #eee;}}.login_form {position: absolute;bottom: 60px;width: 100%;padding: 0 20px;box-sizing: border-box; }.btns {display: flex;justify-content: center; } </style>main.js
import Vue from 'vue' import App from './App.vue' import router from './router' import './plugins/element.js' //導(dǎo)入字體圖標(biāo) import './assets/fonts/iconfont.css' Vue.config.productionTip = false //導(dǎo)入全局樣式 import './assets/css/global.css' import TreeTable from "vue-table-with-tree-grid" import axios from 'axios'Vue.prototype.$http=axios axios.defaults.baseURL="http://127.0.0.1:8888/api/private/v1/" // 請(qǐng)求在到達(dá)服務(wù)器之前,先會(huì)調(diào)用use中的這個(gè)回調(diào)函數(shù)來(lái)添加請(qǐng)求頭信息 axios.interceptors.request.use(config => {// console.log(config)// 為請(qǐng)求頭對(duì)象,添加token驗(yàn)證的Authorization字段config.headers.Authorization = window.sessionStorage.getItem('token')// 在最后必須 return configreturn config }) Vue.config.productionTip=false; Vue.component('tree-table',TreeTable)Vue.filter('dataFormat', function (originVal) {const dt = new Date(originVal)const y = dt.getFullYear()const m = (dt.getMonth() + 1 + '').padStart(2, '0')const d = (dt.getDate() + '').padStart(2, '0')const hh = (dt.getHours() + '').padStart(2, '0')const mm = (dt.getMinutes() + '').padStart(2, '0')const ss = (dt.getSeconds() + '').padStart(2, '0')// yyyy-mm-dd hh:mm:ssreturn `${y}-${m}-$ze8trgl8bvbq ${hh}:${mm}:${ss}` }) new Vue({router,render: h => h(App) }).$mount('#app')global.css
/* 全局樣式 */ html, body, #app {height: 100%;margin: 0;padding: 0;}.el-breadcrumb {margin-bottom: 15px;font-size: 12px; }.el-card {box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important; }.el-table {margin-top: 15px;font-size: 12px; }.el-pagination {margin-top: 15px; }element.js
import Vue from 'vue'//彈框提示 import {Message,Button,Form,FormItem,Input,Container,Header,Aside,Main,Menu,Submenu,MenuItemGroup,MenuItem,Breadcrumb,BreadcrumbItem,Card,Row,Col,Table,TableColumn,Switch,Tooltip,Pagination,Dialog,MessageBox,Tag,Tree } from 'element-ui' Vue.use(Button) Vue.use(Form) Vue.use(FormItem) Vue.use(Input) Vue.use(Container) Vue.use(Header) Vue.use(Aside) Vue.use(Main) Vue.use(Menu) Vue.use(Submenu) Vue.use(MenuItemGroup) Vue.use(MenuItem) Vue.use(Breadcrumb) Vue.use(BreadcrumbItem) Vue.use(Card) Vue.use(Row) Vue.use(Col) Vue.use(Table) Vue.use(TableColumn) Vue.use(Switch) Vue.use(Tooltip) Vue.use(Pagination) Vue.use(Dialog) Vue.use(Tag) Vue.use(Tree) Vue.prototype.$confirm=MessageBox Vue.prototype.$message = MessageHome.vue
import Vue from 'vue' import Router from 'vue-router' import Login from './components/Login.vue' import Home from './components/Home.vue' import Welcome from './components/Welcome.vue' import Users from './components/user/Users.vue' Vue.use(Router)const router = new Router({routes: [{path: '/',redirect: '/login'},{path: '/login',component: Login},{path: '/home',component: Home,redirect: '/welcome',children: [{path: '/welcome',component: Welcome}, {path: '/users',component: Users}]}] }); //掛載路由導(dǎo)航守衛(wèi) router.beforeEach((to, from, next) => {if (to.path === '/login') return next();//獲取tokenconst tokenStr = window.sessionStorage.getItem('token')if (!tokenStr) return next('/login')next(); })export default router.prettierrc
{"semi":false,"singleQuote":true }eslintrc.js
module.exports = {root: true,env: {node: true},extends: ['plugin:vue/essential','@vue/standard'],parserOptions: {parser: 'babel-eslint'},rules: {'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off','no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off','space-before-function-paren':0} }welcome.vue
<template><div><h3>歡迎</h3></div> </template>Users.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>用戶(hù)管理</el-breadcrumb-item><el-breadcrumb-item>用戶(hù)列表</el-breadcrumb-item></el-breadcrumb><el-card><el-row :gutter="20"><el-col :span="7"><el-input placeholder="請(qǐng)輸入內(nèi)容" v-model="queryInfo.query" clearable @clear="getUserList"><el-button slot="append" icon="el-icon-search" @click="getUserList"></el-button></el-input></el-col><el-col :span="4"><el-button type="primary" @click="addDialogVisible=true">添加用戶(hù)</el-button></el-col></el-row><el-table border stripe :data="userlist"><el-table-column type="index" label="#"></el-table-column><el-table-column prop="username" label="姓名"></el-table-column><el-table-column prop="email" label="郵箱"></el-table-column><el-table-column prop="mobile" label="電話"></el-table-column><el-table-column prop="role_name" label="角色"></el-table-column><el-table-column label="狀態(tài)"><template slot-scope="scope"><el-switch v-model="scope.row.mg_state" @change="userStateChanged(scope.row)"></el-switch></template></el-table-column><el-table-column label="操作" width="180px"><template slot-scope="scope"><el-buttontype="primary"icon="el-icon-edit"size="mini"circle@click="showEditDialog(scope.row.id)"></el-button><el-button type="danger" icon="el-icon-delete" size="mini" circle@click="removeUserById(scope.row.id)"></el-button><el-tooltipclass="item"effect="dark"content="角色分配":enterable="false"placement="top"><el-button type="warning" icon="el-icon-setting" size="mini" circle@click="showSetRole(scope.row)"></el-button></el-tooltip></template></el-table-column></el-table><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="queryInfo.pagenum":page-sizes="[2, 5, 10, 15]":page-size="queryInfo.pagesize"layout="total, sizes, prev, pager, next, jumper":total="total"></el-pagination></el-card><!-- 添加用戶(hù)的對(duì)話框 --><el-dialog title="添加用戶(hù)" :visible.sync="addDialogVisible" width="50%" @close="addDialogClosed"><!-- 內(nèi)容主體 --><el-form :model="addForm" ref="addFormRef" :rules="addFormRules" label-width="70px"><el-form-item label="用戶(hù)名" prop="username"><el-input v-model="addForm.username"></el-input></el-form-item><el-form-item label="密碼" prop="password"><el-input v-model="addForm.password"></el-input></el-form-item><el-form-item label="郵箱" prop="email"><el-input v-model="addForm.email"></el-input></el-form-item><el-form-item label="手機(jī)" prop="mobile"><el-input v-model="addForm.mobile"></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="addUser">確 定</el-button></span></el-dialog><!-- 修改用戶(hù)的對(duì)話框 --><el-dialogtitle="修改用戶(hù)信息":visible.sync="editDialogVisible"width="50%"@close="editDialogClosed"><el-form :model="editForm" ref="editUserFormRef" :rules="editFormRules" label-width="70px"><el-form-item label="用戶(hù)名"><el-input v-model="editForm.username" disabled></el-input></el-form-item><el-form-item label="郵箱" prop="email"><el-input v-model="editForm.email"></el-input></el-form-item><el-form-item label="手機(jī)" prop="mobile"><el-input v-model="editForm.mobile"></el-input></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="editDialogVisible = false">取 消</el-button><el-button type="primary" @click="editUserInfo">確 定</el-button></span></el-dialog><!-- 分配角色對(duì)話框 --><el-dialog title="分配角色" :visible.sync="setRoleDialogVisible" width="50%" ><div><p>當(dāng)前用戶(hù):{{userInfo.username}}</p><p>當(dāng)前角色:{{userInfo.role_name}}</p></div><p>分配角色:<el-selectv-model="selectRoleId"filterableallow-createdefault-first-optionplaceholder="請(qǐng)選擇文章標(biāo)簽"><el-optionv-for="item in rolelist":key="item.id":label="item.roleName":value="item.id"></el-option></el-select></p><span slot="footer" class="dialog-footer"><el-button @click="setRoleDialogVisible = false">取 消</el-button><el-button type="primary" @click="saveRoleInfo">確 定</el-button></span></el-dialog></div> </template><style scoped="less" scoped> </style><script> export default {data() {// 自定義郵箱規(guī)則var checkEmail = (rule, value, callback) => {const regEmail = /^\w+@\w+(\.\w+)+$/if (regEmail.test(value)) {// 合法郵箱return callback()}callback(new Error('請(qǐng)輸入合法郵箱'))}// 自定義手機(jī)號(hào)規(guī)則var checkMobile = (rule, value, callback) => {const regMobile = /^1[34578]\d{9}$/if (regMobile.test(value)) {return callback()}// 返回一個(gè)錯(cuò)誤提示callback(new Error('請(qǐng)輸入合法的手機(jī)號(hào)碼'))}return {queryInfo: {query: '',pagenum: 1,pagesize: 2,},userlist: [],total: 0,addDialogVisible: false,addForm: {username: '',password: '',email: '',mobile: '',},addFormRules: {username: [{ required: true, message: '請(qǐng)輸入用戶(hù)名', trigger: 'blur' },{min: 2,max: 10,message: '用戶(hù)名的長(zhǎng)度在2~10個(gè)字',trigger: 'blur',},],password: [{ required: true, message: '請(qǐng)輸入用戶(hù)密碼', trigger: 'blur' },{min: 6,max: 18,message: '用戶(hù)密碼的長(zhǎng)度在6~18個(gè)字',trigger: 'blur',},],email: [{ required: true, message: '請(qǐng)輸入郵箱', trigger: 'blur' },{ validator: checkEmail, trigger: 'blur' },],mobile: [{ required: true, message: '請(qǐng)輸入手機(jī)號(hào)碼', trigger: 'blur' },{ validator: checkMobile, trigger: 'blur' },],},editFormRules: {email: [{ required: true, message: '請(qǐng)輸入郵箱', trigger: 'blur' },{ validator: checkEmail, trigger: 'blur' },],mobile: [{ required: true, message: '請(qǐng)輸入手機(jī)號(hào)碼', trigger: 'blur' },{ validator: checkMobile, trigger: 'blur' },],},editDialogVisible: false,editForm: {},setRoleDialogVisible:false,userInfo:{},rolelist:[],selectRoleId:''}},created() {this.getUserList()},methods: {async getUserList() {const { data: res } = await this.$http.get('users', {params: this.queryInfo,})if (res.meta.status !== 200) {return this.$message.error('獲取用戶(hù)列表失敗!')}this.userlist = res.data.usersthis.total = res.data.totalconsole.log(res)},// 監(jiān)聽(tīng)修改用戶(hù)對(duì)話框的關(guān)閉事件editDialogClosed() {this.$refs.editUserFormRef.resetFields()},// 監(jiān)聽(tīng) pagesize改變的事件handleSizeChange(newSize) {// console.log(newSize)this.queryInfo.pagesize = newSizethis.getUserList()},// 監(jiān)聽(tīng) 頁(yè)碼值 改變事件handleCurrentChange(newSize) {// console.log(newSize)this.queryInfo.pagenum = newSizethis.getUserList()},async userStateChanged(userInfo) {// console.log(userInfo)const { data: res } = await this.$http.put(`users/${userInfo.id}/state/${userInfo.mg_state}`)if (res.meta.status !== 200) {userInfo.mg_state = !userInfo.mg_statereturn this.$message.error('更新用戶(hù)狀態(tài)失敗')}this.$message.success('更新用戶(hù)狀態(tài)成功!')},// 監(jiān)聽(tīng) 添加用戶(hù)對(duì)話框的關(guān)閉事件addDialogClosed() {this.$refs.addFormRef.resetFields()},editUserInfo() {this.$refs.editUserFormRef.validate(async (valid) => {if (!valid) returnconst { data: res } = await this.$http.put('users/' + this.editForm.id,{email: this.editForm.email,mobile: this.editForm.mobile,})if (res.meta.status !== 200) {this.$message.error('更新用戶(hù)信息失敗!')}// 隱藏添加用戶(hù)對(duì)話框this.editDialogVisible = falsethis.$message.success('更新用戶(hù)信息成功!')this.getUserList()})},// 編輯用戶(hù)信息async showEditDialog(id) {const { data: res } = await this.$http.get('users/' + id)if (res.meta.status !== 200) {return this.$message.error('查詢(xún)用戶(hù)信息失敗!')}this.editForm = res.datathis.editDialogVisible = true},// 添加用戶(hù)addUser() {// 提交請(qǐng)求前,表單預(yù)驗(yàn)證this.$refs.addFormRef.validate(async (valid) => {// console.log(valid)// 表單預(yù)校驗(yàn)失敗if (!valid) returnconst { data: res } = await this.$http.post('users', this.addForm)if (res.meta.status !== 201) {this.$message.error('添加用戶(hù)失敗!')}this.$message.success('添加用戶(hù)成功!')// 隱藏添加用戶(hù)對(duì)話框this.addDialogVisible = falsethis.getUserList()})}, // 刪除用戶(hù)async removeUserById (id) {const confirmResult = await this.$confirm('此操作將永久刪除該用戶(hù), 是否繼續(xù)?','提示',{confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning'}).catch(err => err)// 點(diǎn)擊確定 返回值為:confirm// 點(diǎn)擊取消 返回值為: cancelif (confirmResult !== 'confirm') {return this.$message.info('已取消刪除')}const { data: res } = await this.$http.delete('users/' + id)if (res.meta.status !== 200) return this.$message.error('刪除用戶(hù)失敗!')this.$message.success('刪除用戶(hù)成功!')this.getUserList()},async showSetRole (userInfo) {this.userInfo = userInfo// 展示對(duì)話框之前,獲取所有角色列表const { data: res } = await this.$http.get('roles')if (res.meta.status !== 200) {return this.$message.error('獲取角色列表失敗!')}this.rolelist = res.datathis.setRoleDialogVisible = true} , // 分配角色async saveRoleInfo () {if (!this.selectRoleId) {return this.$message.error('請(qǐng)選擇要分配的角色')}const { data: res } = await this.$http.put(`users/${this.userInfo.id}/role`, { rid: this.selectRoleId })if (res.meta.status !== 200) {return this.$message.error('更新用戶(hù)角色失敗!')}this.$message.success('更新角色成功!')this.getUserList()this.setRoleDialogVisible = false},}, } </script>Right.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>權(quán)限管理</el-breadcrumb-item><el-breadcrumb-item>權(quán)限列表</el-breadcrumb-item></el-breadcrumb><el-card><el-table :data="rightsList"><el-table-column type="index" label="#"></el-table-column><el-table-column label="權(quán)限名稱(chēng)" prop="authName"></el-table-column><el-table-column label="路徑" prop="path"></el-table-column><el-table-column label="權(quán)限等級(jí)" prop="level"><template slot-scope="scope"><el-tag v-if="scope.row.level === '0'">一級(jí)</el-tag><el-tag type="success" v-else-if="scope.row.level === '1'">二級(jí)</el-tag><el-tag type="danger" v-else>三級(jí)</el-tag></template></el-table-column></el-table></el-card></div> </template><style lang="less" scoped> </style><script> export default {data(){return{//權(quán)限列表rightsList:[]}},created(){this.getRightList()},methods:{//獲取權(quán)限列表async getRightList(){const {data:res}= await this.$http.get('rights/list')if(res.meta.status!==200){return this.$message.console.error("獲取權(quán)限列表失敗");}this.rightsList=res.data}} } </script>Roles.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>權(quán)限管理</el-breadcrumb-item><el-breadcrumb-item>角色列表</el-breadcrumb-item></el-breadcrumb><el-card><el-row><el-col><el-button type="primary">添加角色</el-button></el-col></el-row><el-table :data="roleslist" border stripe><el-table-column type="expand"><template slot-scope="scope"><el-row:class="['bdbottom', i1 === 0 ? 'bdtop' : '', 'vcenter']" v-for="(item1, i1) in scope.row.children":key="item1.id"><!-- 一級(jí)權(quán)限 --><el-col :span="5"><el-tag closable @close="removeRightById(scope.row, item1.id)">{{ item1.authName}}</el-tag><i class="el-icon-caret-right"></i></el-col><el-col :span="19"><el-row :class="[i2 === 0 ? '' : 'bdtop','vcenter']"v-for="(item2, i2) in item1.children":key="item2.id"><el-col :span="6 "><el-tagtype="success"closable@close="removeRightById(scope.row, item2.id)">{{ item2.authName }}</el-tag><i class="el-icon-caret-right"></i></el-col><el-col :span="18"><el-tagtype="warning"v-for="(item3) in item2.children":key="item3.id"closable@close="removeRightById(scope.row,item3.id)">{{ item3.authName}}</el-tag></el-col></el-row></el-col></el-row><!--<pre>{{scope.row}}</pre>--></template></el-table-column><!-- 索引列 --><el-table-column type="index" label="#"></el-table-column><el-table-column label="角色名稱(chēng)" prop="roleName"></el-table-column><el-table-column label="角色描述" prop="roleDesc"></el-table-column><el-table-column label="操作" width="300px"><template slot-scope="scope"><el-button type="primary" icon="el-icon-edit" size="mini" >編輯</el-button><el-button type="danger" icon="el-icon-delete" size="mini" >刪除</el-button><el-buttontype="warning"icon="el-icon-setting"size="mini"@click="showSetRightDialog(scope.row)">分配權(quán)限</el-button></template></el-table-column></el-table></el-card><!-- 分配權(quán)限 --><el-dialogtitle="分配權(quán)限":visible.sync="setRightDialogVisible"width="50%"@close="setRightDialogClosede"><el-tree:data="rightslist":props="treeProps"ref="treeRef"show-checkboxnode-key="id"default-expand-all:default-checked-keys="defKeys"></el-tree><span slot="footer" class="dialog-footer"><el-button @click="setRightDialogVisible = false">取 消</el-button><el-button type="primary" @click="allotRights">確 定</el-button></span></el-dialog></div> </template><script> export default {data(){return{//所有角色列表數(shù)據(jù)roleslist:[],setRightDialogVisible:false,rightslist:[],treeProps:{label:'authName',children:'children'},defKeys:[],roleId:''}},created(){this.getRolesList()},methods:{async getRolesList (role,rightId) {const { data: res } = await this.$http.get('roles')if (res.meta.status !== 200) {return this.$message.error('獲取角色列表失敗!')}this.roleslist = res.dataconsole.log(this.roleslist)},async removeRightById () {// 彈框提示 刪除const confirmResult = await this.$confirm('此操作將永久刪除該權(quán)限, 是否繼續(xù)?','提示',{confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning'}).catch(err => err)// 點(diǎn)擊確定 返回值為:confirm// 點(diǎn)擊取消 返回值為: cancelif (confirmResult !== 'confirm') {return this.$message.info('已取消權(quán)限刪除')}const { data: res } = await this.$http.delete(`roles/${role.id}/rights/${rightId}`)if (res.meta.status !== 200) {return this.$message.error('刪除權(quán)限失敗!')}this.roleslist = res.data// 不建議使用//this.getRolesList()role.children=res.data},async showSetRightDialog(role){this.roleId=role.id// 獲取角色的所有權(quán)限const { data: res } = await this.$http.get('rights/tree')if (res.meta.status !== 200) {return this.$message.error('獲取權(quán)限數(shù)據(jù)失敗!')}// 獲取權(quán)限樹(shù)this.rightslist = res.data// console.log(res)// 遞歸獲取三級(jí)節(jié)點(diǎn)的id//this.getLeafkeys(role, this.defKeys)this.getLeafkeys(role,this.defKeys)this.setRightDialogVisible = trueconsole.log(this.rightslist)},// 通過(guò)遞歸 獲取角色下三級(jí)權(quán)限的 id, 并保存到defKeys數(shù)組getLeafkeys (node, arr) {// 沒(méi)有children屬性,則是三級(jí)節(jié)點(diǎn)if (!node.children) {return arr.push(node.id)}node.children.forEach(item => this.getLeafkeys(item, arr))},// 權(quán)限對(duì)話框關(guān)閉事件setRightDialogClosed () {this.rightslist = []},// 添加角色對(duì)話框的關(guān)閉addRoleDialogClosed () {this.$refs.addRoleFormRef.resetFields()},setRightDialogClosede(){this.defKeys=[];},// 分配權(quán)限async allotRights (roleId) {// 獲得當(dāng)前選中和半選中的Idconst keys = [...this.$refs.treeRef.getCheckedKeys(),...this.$refs.treeRef.getHalfCheckedKeys()]// join() 方法用于把數(shù)組中的所有元素放入一個(gè)字符串const idStr = keys.join(',')const { data: res } = await this.$http.post(`roles/${this.roleId}/rights`, { rids: idStr })if (res.meta.status !== 200) { return this.$message.error('分配權(quán)限失敗!') }this.$message.success('分配權(quán)限成功!')this.getRolesList()this.setRightDialogVisible = false}} } </script><style lang="less" scoped> .el-tag {margin: 7px; }.bdtop {border-top: 1px solid #eee; } .bdbottom {border-bottom: 1px solid #eee; } .vcenter {display: flex;align-items: center; } </style>Cate.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>商品管理</el-breadcrumb-item><el-breadcrumb-item>參數(shù)列表</el-breadcrumb-item></el-breadcrumb><el-card><!-- 警告區(qū)域 --><el-alert title="注意:只允許為第三級(jí)分類(lèi)設(shè)置相關(guān)參數(shù)!" type="warning" show-icon :closable="false"></el-alert></el-card></div></template><script> export default {} </script><style lang="less" scoped></style>Params.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>商品管理</el-breadcrumb-item><el-breadcrumb-item>參數(shù)列表</el-breadcrumb-item></el-breadcrumb><el-card><!-- 警告區(qū)域 --><el-alert title="注意:只允許為第三級(jí)分類(lèi)設(shè)置相關(guān)參數(shù)!" type="warning" show-icon :closable="false"></el-alert><!-- 選擇商品分類(lèi)區(qū)域 --><el-row class="cat_opt"><el-col><span>選擇商品分類(lèi):</span><!-- 商品分類(lèi)的級(jí)聯(lián)選擇框 --><el-cascaderv-model="selectedCateKeys":options="cateList":props="cateProps"@change="handleChange"></el-cascader></el-col></el-row><el-tabs v-model="activeName" @tab-click="handleTabsClick"><el-tab-pane label="動(dòng)態(tài)參數(shù)" name="many"><el-buttontype="primary"size="mini":disabled="isBtnDisabled "@click="addDialogVisible=true">添加參數(shù)</el-button><el-table :data="manyTableData" border stripe><el-table-column type="expand"><template slot-scope="scope"><el-tag v-for="(item, i) in scope.row.attr_vals" :key="i" closable@close="handleClose(i,scope.row)">{{item}}</el-tag><!-- 輸入Tag文本框 --><el-inputclass="input-new-tag"v-if="scope.row.inputVisible"v-model="scope.row.inputValue"ref="saveTagInput"size="small"@keyup.enter.native="handleInputConfirm(scope.row)"@blur="handleInputConfirm(scope.row)"></el-input><el-button v-else class="button-new-tag" size="small" @click="showInput(scope.row)">+ New Tag</el-button></template></el-table-column><el-table-column type="index"></el-table-column><el-table-column label="參數(shù)名稱(chēng)" prop="attr_name"></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-buttontype="primary"icon="el-icon-edit"@click="showEditDialog(scope.row.attr_id)"size="mini">編輯</el-button><el-buttontype="danger"icon="el-icon-search"size="mini"@click="removeParams(scope.row.attr_id)">刪除</el-button></template></el-table-column></el-table></el-tab-pane><el-tab-pane label="靜態(tài)屬性" name="only"><el-buttontype="primary"size="mini":disabled="isBtnDisabled"@click="addDialogVisible=true">添加屬性</el-button><el-table :data="onlyTableData" border stripe><el-table-column type="expand"><template slot-scope="scope"><el-tag v-for="(item, i) in scope.row.attr_vals" :key="i" closable@close="handleClose(i,scope.row)">{{item}}</el-tag><!-- 輸入Tag文本框 --><el-inputclass="input-new-tag"v-if="scope.row.inputVisible"v-model="scope.row.inputValue"ref="saveTagInput"size="small"@keyup.enter.native="handleInputConfirm(scope.row)"@blur="handleInputConfirm(scope.row)"></el-input><el-button v-else class="button-new-tag" size="small" @click="showInput(scope.row)">+ New Tag</el-button></template></el-table-column><el-table-column type="index"></el-table-column><el-table-column label="屬性名稱(chēng)" prop="attr_name"></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-buttontype="primary"icon="el-icon-edit"size="mini"@click="showEditDialog(scope.row.attr_id)">編輯</el-button><el-buttontype="danger"icon="el-icon-search"size="mini"@click="removeParams(scope.row.attr_id)">刪除</el-button></template></el-table-column></el-table></el-tab-pane></el-tabs></el-card><el-dialog:title=" '添加' + getTitleText":visible.sync="addDialogVisible"width="50%"@close="addDialogClosed"><el-form :model="addFrom" :rules="addFromRules" ref="addFromRef" label-width="100px"><el-form-item :label="getTitleText" prop="attr_name"><el-input v-model="addFrom.attr_name"></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="addParams">確 定</el-button></span></el-dialog><el-dialog:title=" '修改' + getTitleText":visible.sync="editDialogVisible"width="50%"@close="editDialogClosed"><el-form :model="editFrom" :rules="editFromRules" ref="editFromRef" label-width="100px"><el-form-item :label="getTitleText" prop="attr_name"><el-input v-model="editFrom.attr_name"></el-input></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="editDialogClosed = false">取 消</el-button><el-button type="primary" @click="editParams">確 定</el-button></span></el-dialog></div> </template><script> export default {data() {return {cateList: [],cateProps: {value: 'cat_id',label: 'cat_name',children: 'children'},inputVisible: false,inputValue: '',selectedCateKeys: [],activeName: 'many',manyTableData: [],onlyTableData: [],addDialogVisible: false,editDialogVisible: false,// 修改表單數(shù)據(jù)對(duì)象editFrom: {attr_name: '',},// 修改表單驗(yàn)證規(guī)則editFromRules: {attr_name: [{ required: true, message: '請(qǐng)輸入?yún)?shù)名稱(chēng)', trigger: 'blur' },],},addFrom: {attr_name: '',},// 添加表單的驗(yàn)證規(guī)則addFromRules: {attr_name: [{ required: true, message: '請(qǐng)輸入?yún)?shù)名稱(chēng)', trigger: 'blur' },],},}},created() {this.getCateList()},computed: {// 按鈕需要被禁用返回true, 否則返回falseisBtnDisabled() {if (this.selectedCateKeys.length !== 3) {return true}return false},cateId() {if (this.selectedCateKeys.length === 3) {return this.selectedCateKeys[2]}return null},getTitleText() {if (this.activeName === 'many') {return '動(dòng)態(tài)參數(shù)'}return '靜態(tài)屬性'},},methods: {// 獲取所有的商品分類(lèi)列表async getCateList() {const { data: res } = await this.$http.get('categories')if (res.meta.status !== 200) {return this.$message.error('獲取商品數(shù)據(jù)列表失敗!')}this.cateList = res.dataconsole.log(this.cateList)}, // 級(jí)聯(lián)選擇框 選中變化 觸發(fā)async handleChange() {this.getParamsData()},handleInputConfirm() {console.log(ok)},// 刪除對(duì)應(yīng)的參數(shù)可選項(xiàng)handleClose (i, row) {row.attr_vals.splice(i, 1)this.saveAttrVals(row)},async getParamsData() {if (this.selectedCateKeys.length !== 3) {this.selectedCateKeys = []this.manyTableData=[]this.onlyTableData=[]return}console.log(this.selectedCateKeys)const { data: res } = await this.$http.get(`categories/${this.cateId}/attributes`,{params: { sel: this.activeName },})if (res.meta.status !== 200) {return this.$message.error('獲取參數(shù)列表失敗!')}res.data.forEach((item) => {// 通過(guò)三元表達(dá)式判斷attr_vals是否為空item.attr_vals = item.attr_vals ? item.attr_vals.split(' ') : []// 控制文本框的顯示與隱藏item.inputVisible = false// 文本框的輸入值item.inputValue = ''})console.log(res.data)if (this.activeName === 'many') {this.manyTableData = res.data} else {this.onlyTableData = res.data}},handleTabsClick() {// console.log(this.activeName)this.getParamsData()},addDialogClosed() {this.$refs.addFromRef.resetFields()}, // 添加參數(shù)addParams() {this.$refs.addFromRef.validate(async (valid) => {if (!valid) returnconst { data: res } = await this.$http.post(`categories/${this.cateId}/attributes`,{attr_name: this.addFrom.attr_name,attr_sel: this.activeName,})if (res.meta.status !== 201) {return this.$message.error('添加參數(shù)失敗!')}this.$message.success('添加參數(shù)成功!')this.addDialogVisible = falsethis.getParamsData()})},editDialogClosed() {this.$refs.editFromRef.resetFields()},showInput(row) {row.inputVisible = true// $nextTick方法的作用:當(dāng)頁(yè)面元素被重新渲染之后,才會(huì)至指定回調(diào)函數(shù)中的代碼this.$nextTick(_ => {this.$refs.saveTagInput.$refs.input.focus()})},editParams() {this.$refs.editFromRef.validate(async (valid) => {if (!valid) returnconst { data: res } = await this.$http.put(`categories/${this.cateId}/attributes/${this.editFrom.attr_id}`,{attr_name: this.editFrom.attr_name,attr_sel: this.activeName,})if (res.meta.status !== 200) {return this.$message.error('修改參數(shù)失敗!')}this.$message.success('修改參數(shù)成功!')this.getParamsData()this.editDialogVisible = false})},async showEditDialog(attr_id) {const { data: res } = await this.$http.get(`categories/${this.cateId}/attributes/${attr_id}`,{params: { attr_sel: this.activeName },})if (res.meta.status !== 200) {return this.$message.error('獲取分類(lèi)失敗!')}this.editFrom = res.datathis.editDialogVisible = true}, // 根據(jù)Id刪除對(duì)應(yīng)的參數(shù)項(xiàng)async removeParams(attr_id) {const confirmResult = await this.$confirm('此操作將永久刪除該參數(shù), 是否繼續(xù)?','提示',{confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning',}).catch((err) => err)if (confirmResult !== 'confirm') {return this.$message.info('已取消刪除!')}const { data: res } = await this.$http.delete(`categories/${this.cateId}/attributes/${attr_id}`)if (res.meta.status !== 200) {return this.$message.error('刪除參數(shù)失敗!')}this.$message.success('刪除參數(shù)成功!')this.getParamsData()},// 文本框失去焦點(diǎn),或者按下Enter觸發(fā)handleInputConfirm (row) {// 輸入的內(nèi)容為空時(shí),清空if (row.inputValue.trim().length === 0) {row.inputValue = ''row.inputVisible = falsereturn}row.attr_vals.push(row.inputValue.trim())row.inputValue = ''row.inputVisible = false// 提交數(shù)據(jù)庫(kù),保存修改this.saveAttrVals(row)},// 將對(duì)attr_vals(Tag) 的操作 保存到數(shù)據(jù)庫(kù)async saveAttrVals (row) {const { data: res } = await this.$http.put(`categories/${this.cateId}/attributes/${row.attr_id}`,{attr_name: row.attr_name,attr_sel: row.attr_sel,attr_vals: row.attr_vals.join(' ')})if (res.meta.status !== 200) {return this.$message.error('修改參數(shù)項(xiàng)失敗!')}this.$message.success('修改參數(shù)項(xiàng)成功!')},}, } </script><style lang="less" scoped> .cat_opt {margin: 15px 0px; } .el-cascader {width: 25%; } .el-tag {margin: 8px; } .input-new-tag {width: 90px; } </style>List.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>商品管理</el-breadcrumb-item><el-breadcrumb-item>商品列表</el-breadcrumb-item></el-breadcrumb><!-- 卡片視圖 --><el-card><el-row :gutter="20"><el-col :span="6"><el-input placeholder="請(qǐng)輸入內(nèi)容" v-model="queryInfo.query" clearable @clear="getGoodsList"><el-button slot="append" icon="el-icon-search" @click="getGoodsList"></el-button></el-input></el-col><el-col :span="4"><el-button type="primary" @click="goAddPage">添加商品</el-button></el-col></el-row><!-- 表格數(shù)據(jù) --><el-table :data="goodsList" border stripe><el-table-column type="index"></el-table-column><el-table-column label="商品名稱(chēng)" prop="goods_name"></el-table-column><el-table-column label="商品價(jià)格(元)" prop="goods_price" width="100px"></el-table-column><el-table-column label="商品重量" prop="goods_weight" width="70px"></el-table-column><el-table-column label="商品數(shù)量" prop="goods_number" width="70px"></el-table-column><el-table-column label="創(chuàng)建時(shí)間" prop="add_time" width="140px"><template slot-scope="scope">{{scope.row.add_time | dataFormat }}</template></el-table-column><el-table-column label="操作" width="130px"><template slot-scope="scope"><el-button type="primary" icon="el-icon-edit" size="mini"></el-button><el-buttontype="danger"icon="el-icon-delete"size="mini"@click="removeById(scope.row.goods_id)"></el-button></template></el-table-column></el-table><!-- 分頁(yè)區(qū)域 --><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="queryInfo.pagenum":page-sizes="[5, 10, 15, 20]":page-size="queryInfo.pagesize"layout="total, sizes, prev, pager, next, jumper":total="total"background></el-pagination></el-card></div> </template><script> export default {data () {return {queryInfo: {query: '',pagenum: 1,pagesize: 10},// 商品列表goodsList: [],// 商品總數(shù)total: 0}},created () {this.getGoodsList()},methods: {// 根據(jù)分頁(yè)獲取對(duì)應(yīng)的商品列表async getGoodsList () {const { data: res } = await this.$http.get('goods', {params: this.queryInfo})if (res.meta.status !== 200) {return this.$message.error('獲取商品列表失敗!')}this.goodsList = res.data.goods// console.log(this.goodsList)this.total = res.data.total},handleSizeChange (newSize) {this.queryInfo.pagesize = newSizethis.getGoodsList()},handleCurrentChange (newSize) {this.queryInfo.pagenum = newSizethis.getGoodsList()},// 通過(guò)Id刪除商品async removeById (id) {const confirmResult = await this.$confirm('此操作將永久刪除該商品, 是否繼續(xù)?','提示',{confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning'}).catch(err => err)if (confirmResult !== 'confirm') {return this.$message.info('已取消刪除!')}const { data: res } = await this.$http.delete('goods/' + id)if (res.meta.status !== 200) {return this.$message.error('刪除商品失敗!')}this.$message.success('刪除商品成功!')this.getGoodsList()},goAddPage () {this.$router.push('/goods/add')}} } </script><style lang="less" scoped> </style>Add.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>商品管理</el-breadcrumb-item><el-breadcrumb-item>添加商品</el-breadcrumb-item></el-breadcrumb><el-card><!-- 提示 --><el-alert title="添加商品信息" type="info" center show-icon :closable="false"></el-alert><!-- 步驟條 --><el-steps :space="200" :active="activeIndex-0" finish-status="success" align-center><el-step title="基本信息"></el-step><el-step title="商品參數(shù)"></el-step><el-step title="商品屬性"></el-step><el-step title="商品圖片"></el-step><el-step title="商品內(nèi)容"></el-step><el-step title="完成"></el-step></el-steps><el-form:model="addForm":rules="addFormRules"ref="addFormRef"label-width="100px"label-position="top"><el-tabsv-model="activeIndex":tab-position="'left'":before-leave="beforeTabLeave"@tab-click="tabClicked"><el-tab-pane label="基本信息" name="0"><el-form-item label="商品名稱(chēng)" prop="goods_name"><el-input v-model="addForm.goods_name"></el-input></el-form-item><el-form-item label="商品價(jià)格" prop="goods_price"><el-input v-model="addForm.goods_price" type="number"></el-input></el-form-item><el-form-item label="商品重量" prop="goods_weight"><el-input v-model="addForm.goods_weight" type="number"></el-input></el-form-item><el-form-item label="商品數(shù)量" prop="goods_number"><el-input v-model="addForm.goods_number" type="number"></el-input></el-form-item><el-form-item label="商品分類(lèi)" prop="goods_cat"><el-cascaderexpand-trigger="hover"v-model="addForm.goods_cat":options="cateList":props="cateProps"@change="handleChange"></el-cascader></el-form-item></el-tab-pane><el-tab-pane label="商品參數(shù)" name="1"><!-- 渲染表單的Item項(xiàng) --><el-form-itemv-for="item in manyTableData":key="item.attr_id":label="item.attr_name"><!-- 復(fù)選框組 --><el-checkbox-group v-model="item.attr_vals"><el-checkbox :label="cb" v-for="(cb, i) in item.attr_vals" :key="i" border></el-checkbox></el-checkbox-group></el-form-item></el-tab-pane><el-tab-pane label="商品屬性" name="2"><el-form-item :label="item.attr_name" v-for="item in onlyTableData" :key="item.attr_id"><el-input v-model="item.attr_vals"></el-input></el-form-item></el-tab-pane><el-tab-pane label="商品圖片" name="3"><!-- action: 圖片上傳的API接口地址 --><el-upload:action="uploadURL":on-preview="handlePreview":on-remove="handleRemove":headers="headerObj"list-type="picture":on-success="handleSuccess"><el-button size="small" type="primary">點(diǎn)擊上傳</el-button></el-upload></el-tab-pane><el-tab-pane label="商品內(nèi)容" name="4"><!-- 富文本編輯器 --><quill-editor v-model="addForm.goods_introduce"></quill-editor><!-- 添加商品 --><el-button type="primary" class="btnAdd" @click="addGoods">添加商品</el-button></el-tab-pane></el-tabs></el-form></el-card><el-dialog title="圖片預(yù)覽" :visible.sync="previewDialogVisible" width="50%"><img :src="picPreviewPath" alt="" class="previewImg"></el-dialog></div> </template><style lang="less" scoped> .el-checkbox {margin: 0 8px 0 0 !important; } .previewImg{width: 100%; } .btnAdd{margin-top: 15px } </style><script> import _ from 'lodash' export default {data() {return {activeIndex: '0',addForm: {goods_name: '',goods_price: 0,goods_weight: 0,goods_number: 0,// 商品所屬分類(lèi)數(shù)組goods_cat: [],picPreviewPath:'',previewDialogVisible:false,// 圖片的數(shù)組pics: [],// 商品詳情描述goods_introduce: '',attrs: [],},cateList: [],// 圖片上傳地址uploadURL: 'http://127.0.0.1:8888/api/private/v1/upload',// 圖片上傳組件的請(qǐng)求對(duì)象headerObj: {Authorization: window.sessionStorage.getItem('token')},picPreviewPath: '',// 圖片預(yù)覽對(duì)話框previewDialogVisible: false,manyTableData: [],onlyTableData:[],cateProps: {// expandTrigger: 'hover',label: 'cat_name',value: 'cat_id',children: 'children',},addFormRules: {goods_name: [{ required: true, message: '請(qǐng)輸入商品名稱(chēng)', trigger: 'blur' },],goods_price: [{ required: true, message: '請(qǐng)輸入商品價(jià)格', trigger: 'blur' },],goods_weight: [{ required: true, message: '請(qǐng)輸入商品重量', trigger: 'blur' },],goods_number: [{ required: true, message: '請(qǐng)輸入商品數(shù)量', trigger: 'blur' },],goods_cat: [{ required: true, message: '請(qǐng)選擇商品分類(lèi)', trigger: 'blur' },],},}},created() {this.getCateList()},computed: {getCateId() {if (this.addForm.goods_cat.length === 3) {return this.addForm.goods_cat[2]}return null},},methods: {// 獲取商品分類(lèi)數(shù)據(jù)列表async getCateList() {const { data: res } = await this.$http.get('categories')if (res.meta.status !== 200) {return this.$message.error('獲取商品列表失敗!')}this.cateList = res.dataconsole.log(this.cateList)}, // 級(jí)聯(lián)選擇器選中項(xiàng)變化時(shí)出發(fā)handleChange() {if (this.addForm.goods_cat.length !== 3) {this.addForm.goods_cat = []}},beforeTabLeave(activeName, odlActiveName) {// 未選中商品分類(lèi)阻止Tab標(biāo)簽跳轉(zhuǎn)if (odlActiveName === '0' && this.addForm.goods_cat.length !== 3) {this.$message.error('請(qǐng)先選擇商品分類(lèi)')return false}}, // Tab標(biāo)簽被選中時(shí)觸發(fā)// Tab標(biāo)簽被選中時(shí)觸發(fā)async tabClicked () {console.log(this.activeIndex)// 訪問(wèn)動(dòng)態(tài)參數(shù)面板if (this.activeIndex === '1') {const { data: res } = await this.$http.get(`categories/${this.getCateId}/attributes`,{params: { sel: 'many' }})if (res.meta.status !== 200) {return this.$message.error('獲取動(dòng)態(tài)參數(shù)列表失敗!')}res.data.forEach(item => {item.attr_vals =item.attr_vals.length === 0 ? [] : item.attr_vals.split(' ')})console.log(res.data)this.manyTableData = res.data} else if (this.activeIndex === '2') {const { data: res } = await this.$http.get(`categories/${this.getCateId}/attributes`,{params: { sel: 'only' }})if (res.meta.status !== 200) {return this.$message.error('獲取動(dòng)態(tài)參數(shù)列表失敗!')}this.onlyTableData = res.data}},// 處理圖片預(yù)覽handlePreview (file) {this.picPreviewPath = file.response.data.urlthis.previewDialogVisible = true},// 處理移除圖片的操作handleRemove (file) {// 1.獲取將要?jiǎng)h除圖片的臨時(shí)路徑const filePath = file.response.data.tmp_path// 2.從pics數(shù)組中,找到圖片對(duì)應(yīng)的索引值const i = this.addForm.pics.findIndex(x => x.pic === filePath)// 3.調(diào)用splice方法,移除圖片信息this.addForm.splice(i, 1)}, // 監(jiān)聽(tīng)圖片上傳成功事件handleSuccess (response) {// 1.拼接得到一個(gè)圖片信息對(duì)象 臨時(shí)路徑const picInfo = { pic: response.data.tmp_path }// 2.將圖片信息對(duì)象,push到pics數(shù)組中this.addForm.pics.push(picInfo)console.log(this.addForm)},// 添加商品addGoods () {this.$refs.addFormRef.validate(async valid => {if (!valid) return this.$message.error('請(qǐng)?zhí)顚?xiě)必要的表單項(xiàng)!')// 發(fā)送請(qǐng)求前:需對(duì)提交的表單進(jìn)行處理goods_cat attrs// this.addForm.goods_cat = this.addForm.goods_cat.join(',')// 以上寫(xiě)法不對(duì):級(jí)聯(lián)選擇器綁定的對(duì)象goods_cat要求是數(shù)組對(duì)象// 解決辦法: 包:lodash 方法(深拷貝):cloneDeep(boj)// 將this.addForm進(jìn)行深拷貝const form = _.cloneDeep(this.addForm)form.goods_cat = form.goods_cat.join(',')// 處理動(dòng)態(tài)參數(shù)this.manyTableData.forEach(item => {const newInfo = {attr_id: item.attr_id,attr_value: item.attr_vals.join(' ')}this.addForm.attrs.push(newInfo)})// 處理靜態(tài)屬性this.onlyTableData.forEach(item => {const newInfo = {attr_id: item.attr_id,attr_value: item.attr_vals}this.addForm.attrs.push(newInfo)})form.attrs = this.addForm.attrs// 發(fā)起請(qǐng)求添加商品// 商品名稱(chēng)必須是唯一的const { data: res } = await this.$http.post('goods', form)if (res.meta.status !== 201) return this.$message.error('添加商品失敗!')this.$message.success('添加商品成功!')this.$router.push('/goods')})}}, } </script>Order.vue
<template><div><!-- 面包屑導(dǎo)航區(qū) --><el-breadcrumb separator-class="el-icon-arrow-right"><el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item><el-breadcrumb-item>訂單管理</el-breadcrumb-item><el-breadcrumb-item>訂單列表</el-breadcrumb-item></el-breadcrumb><!-- 卡片視圖 --><el-card><el-row><el-col :span="6"><el-input placeholder="請(qǐng)輸入內(nèi)容"><el-button slot="append" icon="el-icon-search"></el-button></el-input></el-col></el-row><!-- 訂單列表 --><el-table :data="orderList" border stripe><el-table-column type="index" label="#"></el-table-column><el-table-column label="訂單編號(hào)" prop="order_number"></el-table-column><el-table-column label="訂單價(jià)格" prop="order_price"></el-table-column><el-table-column label="是否付款"><template slot-scope="scope"><el-tag type="danger" size="mini" v-if="scope.row.pay_status">未付款</el-tag><el-tag type="success" size="mini" v-else>已付款</el-tag></template></el-table-column><el-table-column label="是否發(fā)貨" prop="is_send"></el-table-column><el-table-column label="下單時(shí)間" prop="create_time"></el-table-column><el-table-column label="操作"><template slot><el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditDialog"></el-button><el-buttontype="success"size="mini"icon="el-icon-location"@click="showProgressDialog"></el-button></template></el-table-column></el-table><!-- 分頁(yè)區(qū)域 --><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="queryInfo.pagenum":page-sizes="[5, 10, 15, 20]":page-size="queryInfo.pagesize"layout="total, sizes, prev, pager, next, jumper":total="total"></el-pagination></el-card><!-- 編輯對(duì)話框 --><el-dialogtitle="修改地址":visible.sync="addressDialogVisible"width="50%"@close="addressDialogClosed"><el-form:model="addressForm":rules="addressFormRules"ref="addressFormRef"label-width="100px"><el-form-item label="省市區(qū)/縣" prop="address1"><el-cascaderv-model="addressForm.address1":options="cityData":props="{ expandTrigger: 'hover' }"></el-cascader></el-form-item><el-form-item label="詳細(xì)地址" prop="address2"><el-input v-model="addressForm.address2"></el-input></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="addressDialogVisible = false">取 消</el-button><el-button type="primary" @click="dialogVisible = false">確 定</el-button></span></el-dialog><!-- 展示物流進(jìn)度對(duì)話框 --><el-dialog title="查看物流進(jìn)度" :visible.sync="progressDialogVisible" width="50%"><!-- 時(shí)間線 --><el-timeline><el-timeline-itemv-for="(activity, index) in progressInfo":key="index":timestamp="activity.time">{{activity.context}}</el-timeline-item></el-timeline></el-dialog></div> </template><script> import cityData from './citydata.js'export default {data () {return {// 訂單列表查詢(xún)參數(shù)queryInfo: {query: '',pagenum: 1,pagesize: 10},total: 0,// 訂單列表orderList: [],// 修改地址對(duì)話框addressDialogVisible: false,addressForm: {address1: [],address2: ''},addressFormRules: {address1: [{ required: true, message: '請(qǐng)選擇省市區(qū)縣', trigger: 'blur' }],address2: [{ required: true, message: '請(qǐng)輸入詳細(xì)地址', trigger: 'blur' }]},cityData,// 物流進(jìn)度對(duì)話框progressDialogVisible: false,// 物流進(jìn)度progressInfo: []}},created () {this.getOrderList()},methods: {async getOrderList () {const { data: res } = await this.$http.get('orders', {params: this.queryInfo})if (res.meta.status !== 200) {return this.$message.error('獲取訂單列表失敗!')}this.total = res.data.totalthis.orderList = res.data.goods},// 分頁(yè)handleSizeChange (newSize) {this.queryInfo.pagesize = newSizethis.getOrderList()},handleCurrentChange (newSize) {this.queryInfo.pagenum = newSizethis.getOrderList()},showEditDialog () {this.addressDialogVisible = true},addressDialogClosed () {this.$refs.addressFormRef.resetFields()},async showProgressDialog () {// 供測(cè)試的物流單號(hào):1106975712662const { data: res } = await this.$http.get('/kuaidi/1106975712662')if (res.meta.status !== 200) {return this.$message.error('獲取物流進(jìn)度失敗!')}this.progressInfo = res.datathis.progressDialogVisible = true}} } </script><style lang="less" scoped> .el-cascader {width: 100%; } </style>?
運(yùn)行結(jié)果
?
總結(jié)
以上是生活随笔為你收集整理的前端学习(2028)vue之电商管理系统电商系统之展示物流进度的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python实战教程 | 轻松批量识别数
- 下一篇: 【接口时序】8、DDR3驱动原理与FPG