From 894dd034da2c3b466f0ee80db36342d4b0d01ebc Mon Sep 17 00:00:00 2001
From: 明梦爽 <2972214568@qq.com>
Date: 星期三, 26 一月 2022 23:18:03 +0800
Subject: [PATCH] 管理权限整好

---
 src/components/Administrator/AdMain.vue    |  432 +++++++++++++++++++++++++++++++++++++++
 src/components/page/News.vue               |    5 
 src/api/api.js                             |   23 ++
 src/components/Administrator/Main.vue      |   30 +-
 src/components/Administrator/AdEdit.vue    |   63 +++++
 src/main.js                                |    1 
 src/components/page/zhengce.vue            |    2 
 src/router.js                              |   15 +
 src/components/Administrator/EditLunBo.vue |    9 
 src/components/Login.vue                   |   73 +++---
 10 files changed, 599 insertions(+), 54 deletions(-)

diff --git a/src/api/api.js b/src/api/api.js
index ca3cec2..c867b16 100644
--- a/src/api/api.js
+++ b/src/api/api.js
@@ -62,4 +62,27 @@
     url:'/news/add',
     params:data
   })
+}
+//鐧诲綍
+export const login = data => {
+  return request({
+    method:'POST',
+    url:'/login',
+    params:data
+  })
+}
+//鑾峰彇鏅�氱鐞嗗憳鍒楄〃
+export const getmain = () => {
+  return request({
+    method: 'GET',
+    url:'/admin/list'
+  })
+}
+//瓒呯淇敼鏅璐﹀彿瀵嗙爜
+export const editAccount = data => {
+  return request({
+    method:'POST',
+    url:'/admin/updatePassword',
+    params:data
+  })
 }
\ No newline at end of file
diff --git a/src/components/Administrator/AdEdit.vue b/src/components/Administrator/AdEdit.vue
new file mode 100644
index 0000000..665807a
--- /dev/null
+++ b/src/components/Administrator/AdEdit.vue
@@ -0,0 +1,63 @@
+<template>
+  <div>
+    <el-card class="box-card">
+      <!-- 鏂伴椈琛ㄦ牸鍖哄煙 -->
+      <el-table 
+        :data="tableData"
+        border 
+        style="width: 100%" 
+        :header-cell-style="{textAlign: 'center'}" 
+        :cell-style="{ textAlign: 'center' }"
+      >
+        <el-table-column type="index" label="搴忓彿" width="50">
+          <!-- <template slot-scope="scope">
+            <span>{{ (currentPage-1)*pageSize+scope.$index+1 }}</span>
+          </template> -->
+        </el-table-column>
+        <el-table-column prop="username" label="鏅�氱鐞嗗憳璐﹀彿" width="" >
+        </el-table-column>
+        <el-table-column prop="id" label="id" width="">
+        </el-table-column>
+        <el-table-column label="鎿嶄綔" width="">
+          <template slot-scope="scope">
+            <!-- {{ scope.row.id }} -->
+            <div>
+              <el-button type="success" @click="look(scope.row.id)">娣诲姞</el-button>
+              <el-button type="warning" @click="showEditDialog(scope.row.id)">淇敼</el-button>
+              <el-button type="info" @click="deleteNews(scope.row.id)">鍒犻櫎</el-button>
+            </div>
+          </template>
+          
+        </el-table-column>
+      </el-table>
+    </el-card>
+  </div>
+</template>
+
+<script>
+import { getmain,editAccount } from '../../api/api'
+export default {
+  data() {
+    return {
+      tableData:[], //鏅�氱鐞嗗憳鍒楄〃
+    }
+  },
+  created(){
+    this.ready()
+  },
+  methods:{
+    ready(){
+      getmain().then(res => {
+        console.log(res);
+        if(res.code == 200){
+          this.tableData = res.data
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style lang="less" scoped>
+
+</style>
\ No newline at end of file
diff --git a/src/components/Administrator/AdMain.vue b/src/components/Administrator/AdMain.vue
new file mode 100644
index 0000000..e32dd5b
--- /dev/null
+++ b/src/components/Administrator/AdMain.vue
@@ -0,0 +1,432 @@
+<template>
+  <div>
+    <!-- 绾ц仈閫夋嫨鍣� -->
+    <el-row class="block">
+      <el-col :span="4">
+        <el-cascader
+          v-model="value"
+          :options="options"
+          clearable
+          filterable
+          :getCheckedNodes="true"
+          @change="handleChange">
+        </el-cascader>
+      </el-col>
+      <el-col :span="5">
+        <el-button type="primary" icon="el-icon-edit" @click="goAdEdit()">鐐瑰嚮瀵规櫘閫氱鐞嗗憳杩涜绠$悊</el-button>
+      </el-col>
+    </el-row>
+    <div>
+      <el-card class="box-card">
+        <el-row :gutter="40">
+          <el-col :span="4">
+            <!-- 娣诲姞鏂伴椈鎸夐挳 -->
+            <el-button el-button class="add" type="success" icon="el-icon-plus" @click="goEdit(newsCategoryId)">鐐瑰嚮鍦ㄨ鍒楄〃涓嬫坊鍔犱竴鏉℃柊闂�</el-button>
+          </el-col>
+          <el-col :span="10">
+            <!-- 鏂伴椈鎼滅储 -->
+            <el-input clearable placeholder="璇疯緭鍏ユ墍瑕佹煡璇㈢殑鏂伴椈鏍囬" v-model="search" class="input-with-select">
+            </el-input>
+          </el-col>
+        </el-row>
+        <!-- 鏂伴椈琛ㄦ牸鍖哄煙 -->
+        <el-table 
+          :data="tableData.filter(data => !search || data.title.toLowerCase().includes(search.toLowerCase()))"
+          border 
+          style="width: 100%" 
+          :header-cell-style="{textAlign: 'center'}" 
+          :cell-style="{ textAlign: 'center' }"
+        >
+          <el-table-column type="index" label="搴忓彿" width="50">
+            <template slot-scope="scope">
+              <span>{{ (currentPage-1)*pageSize+scope.$index+1 }}</span>
+            </template>
+          </el-table-column>
+          <el-table-column prop="releaseTime" label="鏃ユ湡" width="" >
+          </el-table-column>
+          <el-table-column prop="title" label="鏂伴椈鏍囬" width="">
+          </el-table-column>
+          <el-table-column prop="id" label="id" width="">
+          </el-table-column>
+          <el-table-column label="鎿嶄綔" width="">
+            <template slot-scope="scope">
+              <!-- {{ scope.row.id }} -->
+              <div>
+                <el-button type="success" @click="look(scope.row.id)">鏌ョ湅</el-button>
+                <el-button type="warning" @click="showEditDialog(scope.row.id)">淇敼</el-button>
+                <el-button type="info" @click="deleteNews(scope.row.id)">鍒犻櫎</el-button>
+              </div>
+            </template>
+            
+          </el-table-column>
+        </el-table>
+        <!-- 鍒嗛〉 -->
+        <div>
+          <!-- 鑾峰彇鏂伴椈鍒楄〃鍒嗛〉 -->
+          <div>
+            <el-pagination
+              @size-change="handleSizeChange"
+              @current-change="handleCurrentChange"
+              :current-page="currentPage"
+              :page-sizes="[6,12, 18,]"
+              :page-size="100"
+              layout="total, sizes, prev, pager, next, jumper"
+              :total="total">
+            </el-pagination>
+          </div>
+        </div>
+      </el-card>
+      <!-- 淇敼鏂伴椈鐨勫璇濇 -->
+      <el-dialog
+        title="淇敼鏂伴椈"
+        :visible.sync="editDialogVisible"
+        width="50%"
+        :before-close="handleClose">
+        <!-- rules琛ㄥ崟楠岃瘉瑙勫垯锛宺ef褰撳墠琛ㄥ崟鐨勯獙璇佸璞� -->
+        <el-form ref="editFormRef" :model="editForm"  label-width="80px" status-icon>
+          <el-form-item label="id:">
+            <el-input v-model="editForm.id" disabled></el-input>
+          </el-form-item>
+          <el-form-item label="鏂伴椈鏍囬:">
+            <el-input v-model="editForm.title"></el-input>
+          </el-form-item>
+          <el-form-item label="鍙戝竷鏃ユ湡:">
+            <el-date-picker 
+              v-model="editForm.releaseTime" 
+              type="date" 
+              placeholder="璇烽�夋嫨鍙戝竷鏃ユ湡"
+              format="yyyy 骞� MM 鏈� dd 鏃�"
+              value-format="yyyy-MM-dd"
+            ></el-date-picker>
+          </el-form-item>
+        </el-form>
+        <span slot="footer" class="dialog-footer">
+          <el-button @click="editDialogVisible = false">鍙� 娑�</el-button>
+          <el-button type="primary" @click="editNew()">纭� 瀹�</el-button>
+        </span>
+      </el-dialog>
+    </div>
+  </div>
+</template>
+
+<script>
+import { getNewsList,getnew,update,deleteNew,fuzzy } from '../../api/api'
+export default {
+  data() {
+    return {
+      search:'',
+      getShow:true, //鑾峰彇鍒嗛〉鐨勬樉绀�(甯冨皵鍊�)
+      gettable:true,  //鑾峰彇琛ㄦ牸鐨勬樉绀�
+      visible: false,
+      editDialogVisible:false,  //鎺у埗淇敼瀵硅瘽妗嗙殑甯冨皵鍊�
+      AdDialogVisible:false,  //瓒呯鐧诲綍瀵硅瘽妗�
+      Ad:{ username:'',password:'' }, //瓒呯瀵硅薄
+      editForm:{},  //鏌ヨ鍒扮殑鏂伴椈瀵硅薄锛岀洰鍓嶄粎渚涗慨鏀逛娇鐢�
+      newsCategoryId:1, //鍏堝瓨涓�涓皬鏍囬id
+      tableData:[],   //鏂伴椈鍒楄〃瀵硅薄
+      fuzzytableData:[],  //妯$硦鏌ヨ鍒楄〃瀵硅薄
+      pageSize:6,     //姣忛〉鏉℃暟
+      currentPage:1,  //褰撳墠椤�
+      total:0,        //鏂伴椈鎬绘潯鏁�
+      fuzzyShow:false,  //妯$硦鏌ヨ鍒嗛〉鐨勬樉绀�(甯冨皵鍊�)
+      fuzzytable:false, //妯$硦鏌ヨ琛ㄦ牸鐨勬樉绀�
+      fuzzyForm:{ fuzzytitle:'',fuzzytotal:0,fuzzycurrent:1,fuzzysize:6 },  //妯$硦鏌ヨ鍒楄〃瀵硅薄
+      value: [],
+      options: [{
+        value: 1,
+        label: '棣栭〉',
+        children: [{
+          value:42,
+          label: '閫氱煡鍏憡',
+        }, 
+        {
+          value:43,
+          label: '宸ヤ綔鍔ㄦ��',
+        },
+        {
+          value:44,
+          label: '瀛﹂櫌鍔ㄦ��',
+        },
+        {
+          value:45,
+          label: '杞挱鍥�',
+        }],
+      },{
+          value: 22,
+          label: '绉戝崗姒傚喌',
+          children: [{
+            value:27,
+            label: '绠�浠�',
+          }, 
+          {
+            value:28,
+            label: '绔犵▼',
+          },
+          {
+            value:29,
+            label: '缁勭粐缁撴瀯',
+          },
+          {
+            value:30,
+            label: '宸ヤ綔鑱岃矗',
+          },
+          {
+            value:31,
+            label: '涓撹亴浜哄憳',
+          }],
+        },
+        {
+          value: 23,
+          label: '鏀跨瓥娉曡',
+          children: [{
+            value:35,
+            label: '涓浗绉戝崗鏀跨瓥鏂囦欢',
+          }, 
+          {
+            value:36,
+            label: '鍦版柟绉戝崗鏀跨瓥鏂囦欢',
+          },
+          {
+            value:37,
+            label: '绀惧洟绠$悊鏂囦欢',
+          }],
+        },
+        {
+          value: 25,
+          label: '瀛︽湳浜ゆ祦',
+          children: [{
+            value:38,
+            label: '瀛︽湳淇℃伅',
+          }, 
+          {
+            value:39,
+            label: '绉戞妧绔炶禌',
+          }],
+        },
+        {
+          value: 27,
+          label: '绉戞櫘椋庨噰',
+          children: [{
+            value:40,
+            label: '骞抽《灞卞闄㈢鏅椿鍔�',
+          }, 
+          {
+            value:41,
+            label: '骞抽《灞卞競鏀垮崗绉戞櫘娲诲姩',
+          }],
+      }]
+    }
+  },
+  created(){
+  },
+  mounted(){
+  },
+  methods: {
+    //淇敼瀵硅瘽妗嗗叧闂殑鏂规硶
+    handleClose(done) {
+      this.$confirm('纭鍏抽棴锛�')
+        .then(_ => {
+          done();
+        })
+        .catch(_ => {});
+    },
+    //璺宠浆鏅�氱鐞嗗垪琛�
+    goAdEdit(){
+      this.$router.push({path:'adedit'})
+    },
+    //绾ц仈閫夋嫨鍣ㄧ殑鏂规硶
+    handleChange(value) {
+      // console.log(value);
+      // console.log(value[1]);
+      this.currentPage = 1;
+      this.newsCategoryId = value[1]; //灏嗗緱鍒扮殑灏忔爣棰榠d瀛樻斁璧锋潵
+      this.query(this.newsCategoryId);
+    },
+    query(newsCategoryId){
+      const data = {
+        current:this.currentPage,
+        newsCategoryId:newsCategoryId,
+        size:this.pageSize
+      };
+      getNewsList(data).then(res=>{
+        // console.log(res);
+        if (res.code !== 200) {
+          return this.$message.error('鑾峰彇鏂伴椈鍒楄〃澶辫触')
+        }else{
+          this.tableData = res.data.records
+          this.total = res.data.total
+        }
+      }).catch(err => {
+        console.log(err);
+      })
+    },
+    //灞曠ず淇敼瀵硅瘽妗�
+    showEditDialog(id){
+      getnew(id).then(res => {
+        // console.log(res);
+        if (res.code == 200) {
+          this.editForm = res.data
+        }     
+      })
+      this.editDialogVisible = true;
+    },
+    //纭畾淇敼琛ㄥ崟鎻愪氦锛岄獙璇佸彂璧疯姹�
+    editNew(){
+      const data = {
+        id: this.editForm.id,
+        releaseTime: this.editForm.releaseTime,
+        title:this.editForm.title
+      }
+      update(data).then(res=>{
+        console.log('dsadasas',res);
+        if (res.code == 200) {
+          this.editDialogVisible =false;
+          this.$message.success('淇敼鏂伴椈鎴愬姛锛�')
+          this.query(this.newsCategoryId);
+        }
+      })
+    },
+    //妯$硦鏌ヨ
+    fuzzyList(title){
+      // console.log(title);
+      if(title == ''){
+        return  this.$message.error('璇峰厛杈撳叆鏌ヨ鏂伴椈鏍囬锛�')
+      }
+      this.fuzzyShow = true //妯$硦鍒嗛〉鏄剧ず
+      this.getShow = false  //鑾峰彇鍒嗛〉闅愯棌
+      this.gettable = false
+      this.fuzzytable = true
+      const data = {
+        current: this.fuzzyForm.fuzzycurrent,
+        size: this.fuzzyForm.fuzzysize,
+        title:title
+      }
+      fuzzy(data).then(res => {
+        // console.log(res);
+        if (res.code !== 200) {
+          return this.$message.error('鏌ヨ鏂伴椈鍒楄〃澶辫触')
+        }else{
+          this.fuzzytableData = res.data.records
+          this.fuzzyForm.fuzzytotal = res.data.total
+        }
+      }).catch(err => {
+        console.log(err);
+      })
+    },
+    //娓呯┖鏌ヨ鍒楄〃鍐呭
+    qingKong(){
+      this.tableData = []
+      this.fuzzytableData = []
+      this.fuzzyForm.fuzzytotal = 0
+      this.fuzzyShow = false
+      this.getShow = true
+      this.fuzzytable = false
+      this.gettable = true
+    },
+    //鏍规嵁id鍒犻櫎鏂伴椈
+    async deleteNews(id){
+      // console.log(id);
+      const res = await this.$confirm('姝ゆ搷浣滃皢姘镐箙鍒犻櫎璇ユ潯鏂伴椈, 鏄惁缁х画?', '鎻愮ず', {
+        confirmButtonText: '纭畾',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning'
+      }).catch(err => {
+        return err
+      })
+      //濡傛灉鐢ㄦ埛鐐瑰嚮纭畾鍒欒繑鍥瀋onfirm
+      //濡傛灉鐢ㄦ埛鐐瑰嚮鍙栨秷鍒欒繑鍥瀋ancel
+      console.log(res);
+      if(res !== 'confirm'){
+        return this.$message.info('宸插彇娑堝垹闄')
+      }else{
+        console.log(id);
+        const data = {
+          id:id
+        }
+        //鍙傛暟data 瑕佷互瀵硅薄鐨勫舰寮忎紶鍏�
+        deleteNew(data).then(res => {
+          console.log('>>>'+res);
+          if(res.code == 200){
+            this.$message.success('鍒犻櫎鏂伴椈鎴愬姛锛�')
+            this.query(this.newsCategoryId);
+          }else{
+            return this.$message.error('鍒犻櫎鏂伴椈澶辫触锛�')
+          }
+        })
+      }
+    },
+    //鏌ョ湅
+    look(id){
+      this.$router.push({path:'news',query:{id:id}})
+    },
+    //瓒呯鐧诲綍瀵硅瘽妗�
+    showAdDialog(){
+      this.AdDialogVisible = true
+    },
+    handleCurrentChange(val) {
+      // console.log(`褰撳墠椤�: ${val}`);
+      this.currentPage = val;
+      this.query(this.newsCategoryId)
+    },
+    handleSizeChange(val) {
+      // console.log(`姣忛〉 ${val} 鏉);
+      this.pageSize = val;
+      this.query(this.newsCategoryId)
+    },
+    handleCurrentChangefuzzy(val){
+      this.fuzzyForm.fuzzycurrent = val
+      this.fuzzyList(this.fuzzyForm.fuzzytitle) //妯$硦鏌ヨ
+    },
+    handleSizeChangefuzzy(val){
+      this.fuzzyForm.fuzzysize = val
+      this.fuzzyList(this.fuzzyForm.fuzzytitle) //妯$硦鏌ヨ
+    },
+    //鍘诲線娣诲姞缂栬緫椤甸潰
+    goEdit(id){
+      let title = '';
+      console.log(this.value);
+      if (this.value.length = 2) {
+        let t = this.value[0];
+        let i = this.value[1];
+        this.options.forEach( item => {
+          if(item.value == t){
+            title += item.label+'/'
+            item.children.forEach( e => {
+              if(e.value == i) title += e.label;
+            })
+          }
+        })
+      }
+      if (this.newsCategoryId==27&&this.total==1||this.newsCategoryId==28&&this.total==1||this.newsCategoryId==29&&this.total==1||
+      this.newsCategoryId==30&&this.total==1||this.newsCategoryId==31&&this.total==1) {
+        this.$message.error('璇ユ柊闂绘爣棰樹笅鍙兘瀛樺湪涓�绡囨柊闂�')
+      }else if(this.newsCategoryId==27||this.newsCategoryId==28||this.newsCategoryId==29||this.newsCategoryId==30||
+      this.newsCategoryId==31||this.newsCategoryId == 35||this.newsCategoryId==36||this.newsCategoryId==37||
+      this.newsCategoryId==38||this.newsCategoryId==39||this.newsCategoryId==40||
+      this.newsCategoryId==41||this.newsCategoryId==42||this.newsCategoryId==43||
+      this.newsCategoryId==44){
+        this.$router.push({path:'/administrator/edit',query:{id:id,title:title}})
+        console.log(this.newsCategoryId);
+      }else if(this.newsCategoryId==45){
+        this.$router.push({path:'/administrator/editlunbo',query:{id:id,title:title}})
+        // console.log(this.newsCategoryId);
+      }else{
+        this.$message.error('璇峰厛閫夋嫨鏂伴椈鏍囬')
+      }
+ 
+    }
+  },
+}
+</script>
+
+<style lang="less">
+.add{
+  margin-bottom: 10px !important;
+}
+.block{
+  margin-bottom: 10px;
+}
+.el-pagination{
+  margin-top: 10px;
+}
+</style>
\ No newline at end of file
diff --git a/src/components/Administrator/EditLunBo.vue b/src/components/Administrator/EditLunBo.vue
index a19f534..47900d7 100644
--- a/src/components/Administrator/EditLunBo.vue
+++ b/src/components/Administrator/EditLunBo.vue
@@ -6,7 +6,8 @@
     <el-upload
       class="upload-demo"
       drag
-      action="https://jsonplaceholder.typicode.com/posts/"
+      action="http://localhost:8080//news/add"
+      :on-remove="handleRemove"
       multiple>
       <i class="el-icon-upload"></i>
       <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
@@ -50,12 +51,16 @@
     this.newsCategoryId = this.$route.query.id
   },
   methods:{
+    handleRemove(file,fileList){
+      console.log(file,fileList);
+    },
     submit(){
       const data = {
         newsCategoryId:this.newsCategoryId,
         content:this.content,
         title:this.title,
-        releaseTime:this.releaseTime
+        releaseTime:this.releaseTime,
+        pictureFile:this.file,
       }
       add(data).then(res => {
         console.log(res);
diff --git a/src/components/Administrator/Main.vue b/src/components/Administrator/Main.vue
index 76f7999..2953c2a 100644
--- a/src/components/Administrator/Main.vue
+++ b/src/components/Administrator/Main.vue
@@ -1,16 +1,18 @@
 <template>
   <div>
     <!-- 绾ц仈閫夋嫨鍣� -->
-    <div class="block">
-      <el-cascader
-        v-model="value"
-        :options="options"
-        clearable
-        filterable
-        :getCheckedNodes="true"
-        @change="handleChange">
-      </el-cascader>
-    </div>
+    <el-row class="block">
+      <el-col :span="4">
+        <el-cascader
+          v-model="value"
+          :options="options"
+          clearable
+          filterable
+          :getCheckedNodes="true"
+          @change="handleChange">
+        </el-cascader>
+      </el-col>
+    </el-row>
     <div>
       <el-card class="box-card">
         <el-row :gutter="40">
@@ -114,6 +116,8 @@
       gettable:true,  //鑾峰彇琛ㄦ牸鐨勬樉绀�
       visible: false,
       editDialogVisible:false,  //鎺у埗淇敼瀵硅瘽妗嗙殑甯冨皵鍊�
+      AdDialogVisible:false,  //瓒呯鐧诲綍瀵硅瘽妗�
+      Ad:{ username:'',password:'' }, //瓒呯瀵硅薄
       editForm:{},  //鏌ヨ鍒扮殑鏂伴椈瀵硅薄锛岀洰鍓嶄粎渚涗慨鏀逛娇鐢�
       newsCategoryId:1, //鍏堝瓨涓�涓皬鏍囬id
       tableData:[],   //鏂伴椈鍒楄〃瀵硅薄
@@ -267,7 +271,7 @@
         title:this.editForm.title
       }
       update(data).then(res=>{
-        // console.log('dsadasas',res);
+        console.log('dsadasas',res);
         if (res.code == 200) {
           this.editDialogVisible =false;
           this.$message.success('淇敼鏂伴椈鎴愬姛锛�')
@@ -348,6 +352,10 @@
     look(id){
       this.$router.push({path:'news',query:{id:id}})
     },
+    //瓒呯鐧诲綍瀵硅瘽妗�
+    showAdDialog(){
+      this.AdDialogVisible = true
+    },
     handleCurrentChange(val) {
       // console.log(`褰撳墠椤�: ${val}`);
       this.currentPage = val;
diff --git a/src/components/Login.vue b/src/components/Login.vue
index 9e3bd7d..cd43fda 100644
--- a/src/components/Login.vue
+++ b/src/components/Login.vue
@@ -6,18 +6,18 @@
         <img src="../assets/logo.png" alt="" />
       </div>
       <!-- 鐧诲綍琛ㄥ崟鍖哄煙 -->
-      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form">
+      <el-form ref="loginFormRef" :model="loginForm" label-width="0px" class="login_form">
         <!-- 鐢ㄦ埛鍚� -->
         <el-form-item prop="username">
-          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user"></el-input>
+          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user" placeholder="璇疯緭鍏ヨ处鍙�" clearable></el-input>
         </el-form-item>
         <!-- 瀵嗙爜 -->
         <el-form-item prop="password">
-          <el-input v-model="loginForm.password" prefix-icon="iconfont icon-3702mima" type="password"></el-input>
+          <el-input v-model="loginForm.password" prefix-icon="iconfont icon-3702mima" type="password" show-password placeholder="璇疯緭鍏ュ瘑鐮�"></el-input>
         </el-form-item>
         <!-- 鎸夐挳鍖哄煙 -->
         <el-form-item class="btns">
-          <el-button type="primary" @click="login">鐧诲綍</el-button>
+          <el-button type="primary" @click="Login">鐧诲綍</el-button>
           <el-button type="info" @click="resetLoginForm">閲嶇疆</el-button>
         </el-form-item>
       </el-form>
@@ -26,27 +26,15 @@
 </template>
 
 <script>
+import { login } from '../api/api'
 export default {
   data() {
     return {
       // 杩欐槸鐧诲綍琛ㄥ崟鐨勬暟鎹粦瀹氬璞�
       loginForm: {
-        username: 'admin',
+        username: 'rendong',
         password: '123456'
       },
-      // 杩欐槸琛ㄥ崟鐨勯獙璇佽鍒欏璞�
-      loginFormRules: {
-        // 楠岃瘉鐢ㄦ埛鍚嶆槸鍚﹀悎娉�
-        username: [
-          { required: true, message: '璇疯緭鍏ョ櫥褰曞悕绉�', trigger: 'blur' },
-          { min: 3, max: 10, message: '闀垮害鍦� 3 鍒� 10 涓瓧绗�', trigger: 'blur'}
-        ],
-        // 楠岃瘉瀵嗙爜鏄惁鍚堟硶
-        password: [
-          { required: true, message: '璇疯緭鍏ョ櫥褰曞瘑鐮�', trigger: 'blur' },
-          { min: 6, max: 15, message: '闀垮害鍦� 6 鍒� 15 涓瓧绗�', trigger: 'blur'}
-        ]
-      }
     }
   },
   methods: {
@@ -54,22 +42,41 @@
     resetLoginForm() {
       this.$refs.loginFormRef.resetFields()
     },
-    login() {
-      this.$refs.loginFormRef.validate(async (valid) => {
-        if (!valid) return
-        const { data: res } = await this.$http.post('/login', this.loginForm)
-        console.log('12312123123123123')
-        console.log(res)
-        if (res.meta.status !== 200) return this.$message.error('鐧诲綍澶辫触锛�')
-        this.$message.success('鐧诲綍鎴愬姛')
-        // console.log(res)
-        // 1. 灏嗙櫥褰曟垚鍔熶箣鍚庣殑 token锛屼繚瀛樺埌瀹㈡埛绔殑 sessionStorage 涓�
-        //   1.1 椤圭洰涓嚭浜嗙櫥褰曚箣澶栫殑鍏朵粬API鎺ュ彛锛屽繀椤诲湪鐧诲綍涔嬪悗鎵嶈兘璁块棶
-        //   1.2 token 鍙簲鍦ㄥ綋鍓嶇綉绔欐墦寮�鏈熼棿鐢熸晥锛屾墍浠ュ皢 token 淇濆瓨鍦� sessionStorage 涓�
-        window.sessionStorage.setItem('token', res.data.token)
-        // 2. 閫氳繃缂栫▼寮忓鑸烦杞埌鍚庡彴涓婚〉锛岃矾鐢卞湴鍧�鏄� /home
-        this.$router.push('/administrator/main')
+    Login() {
+      const data = {
+        username: this.loginForm.username,
+        password: this.loginForm.password
+      }
+      login(data).then(res => {
+        console.log(res);
+        if(res.code !== 200){
+          this.$message.error('鐧诲綍澶辫触锛�')
+        }else if(res.data.role == '瓒呯骇绠$悊鍛�'){
+          this.$message.success('瓒呯鐧诲綍鎴愬姛锛�')
+          window.sessionStorage.setItem('token',res.cookie)
+          this.$router.push('/administrator/admain')
+        }else{
+          this.$message.success('鐧诲綍鎴愬姛锛�')
+          window.sessionStorage.setItem('token',res.cookie)
+          this.$router.push('/administrator/main')
+        }
       })
+
+      // this.$refs.loginFormRef.validate(async (valid) => {
+      //   if (!valid) return
+      //   const { data: res } = await this.$http.post('/login', this.loginForm)
+      //   console.log('12312123123123123')
+      //   console.log(res)
+      //   if (res.meta.status !== 200) return this.$message.error('鐧诲綍澶辫触锛�')
+      //   this.$message.success('鐧诲綍鎴愬姛')
+      //   // console.log(res)
+      //   // 1. 灏嗙櫥褰曟垚鍔熶箣鍚庣殑 token锛屼繚瀛樺埌瀹㈡埛绔殑 sessionStorage 涓�
+      //   //   1.1 椤圭洰涓嚭浜嗙櫥褰曚箣澶栫殑鍏朵粬API鎺ュ彛锛屽繀椤诲湪鐧诲綍涔嬪悗鎵嶈兘璁块棶
+      //   //   1.2 token 鍙簲鍦ㄥ綋鍓嶇綉绔欐墦寮�鏈熼棿鐢熸晥锛屾墍浠ュ皢 token 淇濆瓨鍦� sessionStorage 涓�
+      //   window.sessionStorage.setItem('token', res.data.token)
+      //   // 2. 閫氳繃缂栫▼寮忓鑸烦杞埌鍚庡彴涓婚〉锛岃矾鐢卞湴鍧�鏄� /home
+      //   this.$router.push('/administrator/main')
+      // })
     }
   }
 }
diff --git a/src/components/page/News.vue b/src/components/page/News.vue
index be05aef..3d576af 100644
--- a/src/components/page/News.vue
+++ b/src/components/page/News.vue
@@ -6,7 +6,7 @@
       <p>鍙戝竷鏃ユ湡锛歿{ releaseTime }} 鐐瑰嚮閲忥細[ {{hits}} ]</p>
     </div>
     <hr>
-    <div v-html="content" class="content"></div>
+    <div v-html="content"></div>
   </div>
 </template>
 <script>
@@ -54,7 +54,4 @@
   height: 35px;
   line-height: 35px;
 }
-/* .content span{
-  background-color: rgb(0, 0, 0);
-} */
 </style>
\ No newline at end of file
diff --git a/src/components/page/zhengce.vue b/src/components/page/zhengce.vue
index 475dddc..8462a8c 100644
--- a/src/components/page/zhengce.vue
+++ b/src/components/page/zhengce.vue
@@ -116,7 +116,7 @@
     show(item){
       // console.log(item.id);
       this.$router.push({path:'/home/news',query:{id:item.id}})
-    }
+    },
   }
 }
 </script>
diff --git a/src/main.js b/src/main.js
index 49e66c8..ba50c0f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -14,6 +14,7 @@
 // axios.defaults.baseURL = 'http://8.140.68.52:8181'
 // axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
 axios.defaults.baseURL = 'http://localhost:8080/'
+axios.defaults.withCredentials = true;
 axios.interceptors.request.use(config => {
   // console.log(config)
   config.headers.Authorization = window.sessionStorage.getItem('token')
diff --git a/src/router.js b/src/router.js
index 2eae566..84e2fd8 100644
--- a/src/router.js
+++ b/src/router.js
@@ -19,6 +19,8 @@
 import Main from './components/Administrator/Main.vue'
 import Edit from './components/Administrator/Edit.vue'
 import EditLunBo from './components/Administrator/EditLunBo.vue'
+import AdMain from './components/Administrator/AdMain.vue'
+import AdEdit from './components/Administrator/AdEdit.vue'
 
 
 Vue.use(Router)
@@ -33,7 +35,9 @@
                 { path:'main',component:Main },
                 { path:'edit',component:Edit },
                 { path:'news',component:News },
-                { path:'editlunbo',component:EditLunBo }] 
+                { path:'editlunbo',component:EditLunBo },
+                { path:'admain',component:AdMain },
+                { path:'adedit',component:AdEdit }] 
     },
     { 
       path: '/home', 
@@ -115,10 +119,15 @@
   // from 浠h〃浠庡摢涓矾寰勮烦杞�屾潵
   // next 鏄竴涓嚱鏁帮紝琛ㄧず鏀捐
   //     next()  鏀捐    next('/login')  寮哄埗璺宠浆
-
-  if (to.path === '/login') return next()
+  // if (to.path === '/administrator/main' && !tokenStr) return next()
+  // if (to.path === '/home/index') return next()
   // 鑾峰彇token
   const tokenStr = window.sessionStorage.getItem('token')
+  if (to.path === '/administrator/main' && !tokenStr) return next('/login')
+  if (to.path === '/administrator/admain' && !tokenStr) return next('/login')
+  if (to.path === '/administrator' && !tokenStr) return next('/login')
+  if (to.path === '/administrator/edit' && !tokenStr) return next('/login')
+  if (to.path === '/administrator/welcome' && !tokenStr) return next('/login')
   // if (!tokenStr) return next('/login')
   next()
 })

--
Gitblit v1.8.0