Browse Source

feat(auth): 权限完成

tbphp 1 year ago
parent
commit
a6f76fc4e0

+ 1 - 1
index.tpl

@@ -2,7 +2,7 @@
 <html>
   <head>
     <meta charset="utf-8">
-    <title>一兔网后台管理系统-测试修改</title>
+    <title>一兔网后台管理系统</title>
   </head>
   <body>
     <div id="app"></div>

+ 7 - 7
src/components/notice/push.vue

@@ -9,12 +9,12 @@
         <t-btn type="del" :sels="sels" @click="del"/>
       </el-button-group>
     </t-list>
-    <push-edit ref="edit" @reload="$refs.list.reload()"/>
+    <notice-edit ref="edit" @reload="$refs.list.reload()"/>
   </div>
 </template>
 
 <script>
-  import pushEdit from './pushEdit'
+  import noticeEdit from './noticeEdit'
 
   export default {
     data () {
@@ -36,7 +36,7 @@
     },
     methods: {
       add () {
-        this.pushEdit.show('新增')
+        this.noticeEdit.show('新增')
       },
       del (ids) {
         this.$confirm('此操作将删除选中的 '+ids.length+' 条数据, 是否继续?', '提示', {
@@ -51,14 +51,14 @@
       },
       edit (r) {
         this.$http.get('notice/' + r.id).then(data => {
-          this.pushEdit.show('修改', data)
+          this.noticeEdit.show('修改', data)
         }, err => {})
       }
     },
     mounted () {
-      this.pushEdit = this.$refs.edit
-      this.list     = this.$refs.list
+      this.noticeEdit = this.$refs.edit
+      this.list       = this.$refs.list
     },
-    components: {pushEdit}
+    components: {noticeEdit}
   }
 </script>

src/components/notice/pushEdit.vue → src/components/ann/noticeEdit.vue


src/components/notice/tpl.vue → src/components/ann/noticetpl.vue


+ 4 - 8
src/components/notice/tplEdit.vue

@@ -34,14 +34,10 @@
     },
     methods: {
       update () {
-        this.$refs.form.validate(r => {
-          if (r) {
-            this.$http.put('noticetpl/' + this.form.jm, {content: this.form.content, title: this.form.title}).then(data => {
-              this.open = false
-              this.$emit('reload')
-            }, err => {})
-          }
-        })
+        this.$http.put('noticetpl/' + this.form.jm, {content: this.form.content, title: this.form.title}).then(data => {
+          this.open = false
+          this.$emit('reload')
+        }, err => {})
       },
       show (data) {
         this.open = true

+ 19 - 13
src/components/index.vue

@@ -1,12 +1,12 @@
 <template>
   <el-row>
     <el-col :span="12">
-      <el-card class="card">
+      <el-card class="card" v-if="$store.state.base.auth.news">
         <h3><el-button size="mini" type="primary" class="sx" round @click="getnews">刷新</el-button>待处理内容</h3>
         <span v-if="news.length == 0" style="color: gray;font-size: 12px;">无</span>
         <tlink v-for="(n,k) in news" :key="k" :params="n"/>
       </el-card>
-      <el-card class="card">
+      <el-card class="card" v-if="$store.state.base.auth.systems">
         <h3>系统信息</h3>
         <div class="c2">
           <p><label>版本</label>v1.0-release</p>
@@ -21,7 +21,7 @@
       </el-card>
     </el-col>
     <el-col :span="12">
-      <el-card class="card">
+      <el-card class="card" v-if="$store.state.base.auth.counts">
         <h3><el-button size="mini" type="primary" class="sx" round @click="getcounts">刷新</el-button>统计信息</h3>
         <p>
           <label>内容</label>
@@ -60,7 +60,7 @@
           </span>
         </p>
       </el-card>
-      <el-card class="card">
+      <el-card class="card" v-if="$store.state.base.auth.jobs">
         <h3><el-button size="mini" type="primary" class="sx" round @click="getjobs">刷新</el-button>招聘统计</h3>
         <p>
           <label>概览</label>
@@ -125,19 +125,25 @@
     },
     methods: {
       getnews () {
-        this.$http.get('news').then(data => {
-          this.news = data
-        }, err => {})
+        if (this.$store.state.base.auth.news) {
+          this.$http.get('news').then(data => {
+            this.news = data
+          }, err => {})
+        }
       },
       getcounts () {
-        this.$http.get('counts').then(data => {
-          this.counts = data
-        }, err => {})
+        if (this.$store.state.base.auth.counts) {
+          this.$http.get('counts').then(data => {
+            this.counts = data
+          }, err => {})
+        }
       },
       getjobs () {
-        this.$http.get('jobs').then(data => {
-          this.jobs = data
-        }, err => {})
+        if (this.$store.state.base.auth.jobs) {
+          this.$http.get('jobs').then(data => {
+            this.jobs = data
+          }, err => {})
+        }
       }
     },
     created () {

+ 1 - 0
src/components/login.vue

@@ -49,6 +49,7 @@
               localStorage.JWT_TOKEN = data.token
               this.$store.commit('base/setuser', {username: data.username, name: data.name})
               this.$store.commit('base/setmenu', data.menu)
+              this.$store.commit('base/setauth', data.inx_auth)
               this.$store.commit('base/login')
               this.$router.push('/')
             }, err => {})

+ 13 - 2
src/components/system/user.vue

@@ -22,15 +22,20 @@
           <t-btn type="enable" :sels="sels" @click="enable"></t-btn>
           <t-btn type="disabled" :sels="sels" @click="disabled"></t-btn>
         </el-button-group>
-        <el-button type="info" icon="information" size="small" :disabled="!sel" @click="changePwd(sel)">重置密码</el-button>
+        <el-button-group>
+          <el-button type="success" icon="information" size="small" :disabled="!sel" @click="changeAuth(sel)">设置权限</el-button>
+          <el-button type="info" icon="information" size="small" :disabled="!sel" @click="changePwd(sel)">重置密码</el-button>
+        </el-button-group>
       </template>
     </t-list>
     <user-edit ref="useredit" @reload="$refs.list.reload()"/>
+    <user-auth ref="userauth" @reload="$refs.list.reload()"/>
   </div>
 </template>
 
 <script>
   import userEdit from './userEdit'
+  import userAuth from './userAuth'
 
   export default {
     data () {
@@ -91,12 +96,18 @@
             this.list.reload()
           }, err => {})
         }, err => {})
+      },
+      changeAuth (r) {
+        this.$http.get('user/auth/' + r.id).then(data => {
+          this.userAuth.show(r.id, data)
+        }, err => {})
       }
     },
     mounted () {
       this.userEdit = this.$refs.useredit
+      this.userAuth = this.$refs.userauth
       this.list     = this.$refs.list
     },
-    components: {userEdit}
+    components: {userEdit, userAuth}
   }
 </script>

+ 56 - 0
src/components/system/userAuth.vue

@@ -0,0 +1,56 @@
+<template>
+  <el-dialog title="设置权限" :visible.sync="open" width="576px" center>
+    <div class="etree">
+      <el-tree
+        ref="tree"
+        node-key="path"
+        :data="data"
+        :default-checked-keys="sels"
+        show-checkbox
+        @node-click="nclick"
+        default-expand-all>
+      </el-tree>
+    </div>
+    <span slot="footer">
+      <el-button @click="open = false">取 消</el-button>
+      <el-button type="primary" @click="update">更 新</el-button>
+    </span>
+  </el-dialog>
+</template>
+
+<script>
+  export default {
+    data () {
+      return {
+        open: false,
+        uid: 0,
+        data: [],
+        sels: []
+      }
+    },
+    methods: {
+      update () {
+        let data = {auth: JSON.stringify(this.$refs.tree.getCheckedKeys(true))}
+        this.$http.put('user/auth/' + this.uid, data).then(() => {
+          this.open = false
+          this.$emit('reload')
+        }, err => {})
+      },
+      show (uid, data) {
+        this.open = true
+        this.uid  = uid
+        this.data = data.data
+        this.sels = data.sels
+      },
+      nclick (d, n) {
+        if (n.isLeaf) {
+          this.$refs.tree.setChecked(d, !n.checked)
+        }
+      }
+    }
+  }
+</script>
+
+<style scoped>
+  .etree{height: 340px;overflow: auto;}
+</style>

+ 3 - 3
src/lib/router.js

@@ -75,9 +75,9 @@ rule('site/cate', '分类')
 rule('site/equipment', '摄影装备')
 rule('site/profession', '职业')
 rule('site/showpay', '影展支付')
-rule('notice', '公告通知')
-rule('notice/push', '发布公告')
-rule('notice/tpl', '影展通知模板')
+rule('ann', '公告通知')
+rule('ann/notice', '发布公告')
+rule('ann/noticetpl', '影展通知模板')
 rule('service', '服务')
 rule('service/page', '单页')
 rule('service/link', '友情链接')

+ 1 - 0
src/main.js

@@ -30,6 +30,7 @@ if (localStorage.JWT_TOKEN) {
   Vue.http.post('login/check', null, {headers: {'Authorization': localStorage.JWT_TOKEN}}).then(res => {
     store.commit('base/setuser', {username: res.username, name: res.name})
     store.commit('base/setmenu', res.menu)
+    store.commit('base/setauth', res.inx_auth)
     store.commit('base/login')
     Vue.init(store)
   }, err => {

+ 11 - 0
src/store/modules/base.js

@@ -5,6 +5,12 @@ export default {
     islogin: false,
     user: '',
     menu: [],
+    auth: {
+      news: false,
+      counts: false,
+      jobs: false,
+      systems: false
+    },
     switch: true
   },
   mutations: {
@@ -20,6 +26,11 @@ export default {
     [pre + 'setmenu'] (state, data) {
       state.menu = data
     },
+    [pre + 'setauth'] (state, data) {
+      for (let d of data)  {
+        state.auth[d] = true
+      }
+    },
     [pre + 'switch'] (state) {
       state.switch = !state.switch
     }