Browse Source

登录接口+登出100%、资讯接口50%

master
chengxuke 4 years ago
parent
commit
52c9384100

+ 16
- 5
src/api/info.js View File

@@ -1,12 +1,23 @@
1 1
 import axios from '@/libs/api.request'
2
+// 添加
2 3
 export const addInfo = (data) => {
3
-  // const data = {
4
-  //   loginname,
5
-  //   loginpwd
6
-  // }
7 4
   return axios.request({
8
-    url: 'https://aicpapitest.xhkjedu.com/newstype/add',
5
+    url: 'https://aicpapitest.xhkjedu.com/news/add',
9 6
     method: 'POST',
10 7
     data
11 8
   })
12 9
 }
10
+// 获取资讯分类列表
11
+export const classify = (data) => {
12
+  return axios.request({
13
+    url: 'https://aicpapitest.xhkjedu.com/newstype/list',
14
+    method: 'POST'
15
+  })
16
+}
17
+// 获取资讯标签列表
18
+export const tagList = (data) => {
19
+  return axios.request({
20
+    url: 'https://aicpapitest.xhkjedu.com/newstag/list',
21
+    method: 'POST'
22
+  })
23
+}

BIN
src/assets/img/video.png View File


BIN
src/assets/img/videoFace.jpg View File


+ 2
- 2
src/components/editor/editor.vue View File

@@ -62,8 +62,8 @@ export default {
62 62
     // create这个方法一定要在所有配置项之后调用
63 63
     this.editor.create()
64 64
     // 如果本地有存储加载本地存储内容
65
-    let html = this.value || localStorage.editorCache
66
-    if (html) this.editor.txt.html(html)
65
+    // let html = this.value || localStorage.editorCache
66
+    // if (html) this.editor.txt.html(html)
67 67
   }
68 68
 }
69 69
 </script>

+ 1
- 1
src/components/login-form/login-form.vue View File

@@ -67,7 +67,7 @@ export default {
67 67
       // console.log(this.$refs.loginForm)
68 68
       // this.$router.push('home')
69 69
       this.$refs.loginForm.validate((valid) => {
70
-        // console.log(valid)
70
+        console.log(valid)
71 71
         if (valid) {
72 72
           this.$emit('on-success-valid', {
73 73
             loginname: this.form.loginname,

+ 28
- 14
src/components/main/components/navbar/index.vue View File

@@ -18,24 +18,24 @@
18 18
         <div class="drop">
19 19
            <Dropdown  @on-click="handleClick">
20 20
             <a href="javascript:void(0)">
21
-                SHAW-小岩
21
+               {{userInfo.username}}
22 22
             </a>
23 23
             <Dropdown-menu slot="list">
24 24
                 <Dropdown-item>修改密码</Dropdown-item>
25 25
                 <Dropdown-item>修改信息</Dropdown-item>
26 26
                 <Dropdown-item>机构信息</Dropdown-item>
27
-                <Dropdown-item name="logout">退出登录</Dropdown-item>
27
+                <Dropdown-item name="loginout">退出登录</Dropdown-item>
28 28
 
29 29
                 </Dropdown-menu>
30 30
           </Dropdown>
31 31
         </div>
32
-        <a href="#" @click="logout">退出</a>
32
+        <a href="#" @click="loginout">退出</a>
33 33
       </div>
34 34
     </div>
35 35
   </div>
36 36
 </template>
37 37
 <script>
38
-import { mapActions } from 'vuex'
38
+// import { mapActions } from 'vuex'
39 39
 
40 40
 export default {
41 41
   props: {
@@ -44,21 +44,35 @@ export default {
44 44
       default: 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
45 45
     }
46 46
   },
47
+  data () {
48
+    return {
49
+      userInfo: ''
50
+    }
51
+  },
52
+  mounted () {
53
+    this.userInfo = JSON.parse(localStorage.getItem('userInfo')).content
54
+    // console.log(this.userInfo)
55
+  },
47 56
   methods: {
48
-    ...mapActions([
49
-      'handleLogOut'
50
-    ]),
51
-    logout () {
52
-      this.$Message.error('您已被登出!')
53
-      this.handleLogOut().then(() => {
54
-        this.$router.push({
55
-          name: 'login'
56
-        })
57
+    // ...mapActions([
58
+    //   'handleLogOut'
59
+    // ]),
60
+    loginout () {
61
+      this.$store.dispatch('handleLogOut').then(() => {
62
+        this.$router.push({ path: '/login' })
57 63
       })
58 64
     },
65
+    // logout () {
66
+    //   this.$Message.error('您已被登出!')
67
+    //   this.handleLogOut().then(() => {
68
+    //     this.$router.push({
69
+    //       name: 'login'
70
+    //     })
71
+    //   })
72
+    // },
59 73
     handleClick (name) {
60 74
       switch (name) {
61
-        case 'logout': this.logout()
75
+        case 'loginout': this.loginout()
62 76
           break
63 77
         case 'message': this.message()
64 78
           break

+ 1
- 1
src/config/index.js View File

@@ -18,7 +18,7 @@ export default {
18 18
    */
19 19
   baseUrl: {
20 20
     dev: 'https://aicpapitest.xhkjedu.com',
21
-    pro: 'https://api2.xhkjedu.com/mock/7'
21
+    pro: 'https://aicpapitest.xhkjedu.com'
22 22
   },
23 23
   /**
24 24
    * @description 默认打开的首页的路由name值,默认为home

+ 10
- 4
src/libs/axios.js View File

@@ -1,5 +1,7 @@
1 1
 import axios from 'axios'
2 2
 import store from '@/store'
3
+import { getToken } from '@/libs/util'
4
+
3 5
 // import { Spin } from 'iview'
4 6
 const addErrorLog = errorInfo => {
5 7
   const { statusText, status, request: { responseURL } } = errorInfo
@@ -18,16 +20,19 @@ class HttpRequest {
18 20
     this.queue = {}
19 21
   }
20 22
   getInsideConfig () {
23
+    // if (getToken()) {
21 24
     const config = {
22 25
       // baseURL: this.baseUrl,
23 26
       'Header': {
24 27
         'Content-Type': 'application/x-www-form-urlencoded'
25
-      }
28
+      },
26 29
       // 'cookie': [],
27
-      // 'token': '',
28
-      // 'device': 'web',
29
-      // 'uid': '1'
30
+      'token': getToken(),
31
+      'device': 'web',
32
+      'uid': '1'
30 33
     }
34
+    // }
35
+
31 36
     // console.log(config)
32 37
     return config
33 38
   }
@@ -44,6 +49,7 @@ class HttpRequest {
44 49
       if (!Object.keys(this.queue).length) {
45 50
         // Spin.show() // 不建议开启,因为界面不友好
46 51
       }
52
+      // console.log(config)
47 53
       this.queue[url] = true
48 54
       return config
49 55
     }, error => {

+ 7
- 3
src/libs/util.js View File

@@ -2,12 +2,14 @@ import Cookies from 'js-cookie'
2 2
 // cookie保存的天数
3 3
 import config from '@/config'
4 4
 import { forEach, hasOneOf, objEqual } from '@/libs/tools'
5
-const { title, cookieExpires, useI18n } = config
5
+// const { title, cookieExpires, useI18n } = config
6
+const { title, useI18n } = config
6 7
 
7 8
 export const TOKEN_KEY = 'token'
8 9
 
9 10
 export const setToken = (token) => {
10
-  Cookies.set(TOKEN_KEY, token, { expires: cookieExpires || 1 })
11
+  // Cookies.set(TOKEN_KEY, token, { expires: cookieExpires || 1 })
12
+  Cookies.set(TOKEN_KEY, token)
11 13
 }
12 14
 
13 15
 export const getToken = () => {
@@ -15,7 +17,9 @@ export const getToken = () => {
15 17
   if (token) return token
16 18
   else return false
17 19
 }
18
-
20
+export const removeToken = () => {
21
+  return Cookies.remove(TOKEN_KEY)
22
+}
19 23
 export const hasChild = (item) => {
20 24
   return item.children && item.children.length !== 0
21 25
 }

+ 1
- 1
src/locale/lang/zh-CN.js View File

@@ -44,5 +44,5 @@ export default {
44 44
   org_tree_page: '组织结构树',
45 45
   drag_drawer_page: '可拖动抽屉',
46 46
   tree_select_page: '树状下拉选择器',
47
-  Information: '资讯'
47
+  Information: '资讯管理'
48 48
 }

+ 4
- 2
src/router/index.js View File

@@ -45,8 +45,10 @@ router.beforeEach((to, from, next) => {
45 45
       turnTo(to, store.state.user.access, next)
46 46
     } else {
47 47
       // store.dispatch('getUserInfo').then(user => {
48
-      if (store.state.userInfo) {
49
-        turnTo(to, user.access, next)
48
+      // console.log(token)
49
+      if (token && to.name !== LOGIN_PAGE_NAME) {
50
+        // turnTo(to, user.access, next)
51
+        next()
50 52
       } else {
51 53
         setToken('')
52 54
         next({

+ 1
- 1
src/router/routers.js View File

@@ -110,7 +110,7 @@ export default [
110 110
         name: 'Information',
111 111
         meta: {
112 112
           icon: 'ios-create',
113
-          title: '资讯'
113
+          title: '资讯管理'
114 114
         },
115 115
         // component: () => import('@/view/components/editor/editor.vue')
116 116
         component: () => import('@/view/manager/Information/index.vue')

+ 122
- 118
src/store/module/user.js View File

@@ -1,6 +1,6 @@
1 1
 import {
2 2
   login
3
-  // logout,
3
+  // logout
4 4
   // getMessage,
5 5
   // getContentByMsgId,
6 6
   // hasRead,
@@ -8,7 +8,7 @@ import {
8 8
   // restoreTrash,
9 9
   // getUnreadCount
10 10
 } from '@/api/user'
11
-import { setToken, getToken } from '@/libs/util'
11
+import { setToken, getToken, removeToken } from '@/libs/util'
12 12
 import { setStore } from '@/libs/store'
13 13
 
14 14
 export default {
@@ -41,6 +41,7 @@ export default {
41 41
     setToken (state, token) {
42 42
       state.token = token
43 43
       setToken(token)
44
+      // console.log(token)
44 45
     },
45 46
     setUserInfo (state, userInfo) {
46 47
       state.userInfo = userInfo
@@ -71,11 +72,11 @@ export default {
71 72
       state[to].unshift(msgItem)
72 73
     }
73 74
   },
74
-  getters: {
75
-    messageUnreadCount: state => state.messageUnreadList.length,
76
-    messageReadedCount: state => state.messageReadedList.length,
77
-    messageTrashCount: state => state.messageTrashList.length
78
-  },
75
+  // getters: {
76
+  //   messageUnreadCount: state => state.messageUnreadList.length,
77
+  //   messageReadedCount: state => state.messageReadedList.length,
78
+  //   messageTrashCount: state => state.messageTrashList.length
79
+  // },
79 80
   actions: {
80 81
     // 登录
81 82
     handleLogin ({ commit }, { loginname, loginpwd }) {
@@ -103,128 +104,131 @@ export default {
103 104
     // 退出登录
104 105
     handleLogOut ({ state, commit }) {
105 106
       return new Promise((resolve, reject) => {
106
-        logout(state.token).then(() => {
107
-          commit('setToken', '')
108
-          commit('setAccess', [])
109
-          resolve()
110
-        }).catch(err => {
111
-          reject(err)
112
-        })
107
+        // logout(state.token).then(() => {
108
+        commit('setToken', '')
109
+        removeToken()
110
+        state.token = ''
111
+        // console.log(state.token)
112
+        // commit('setAccess', [])
113
+        resolve()
114
+        // }).catch(err => {
115
+        //   reject(err)
116
+        // })
113 117
         // 如果你的退出登录无需请求接口,则可以直接使用下面三行代码而无需使用logout调用接口
114 118
         // commit('setToken', '')
115 119
         // commit('setAccess', [])
116 120
         // resolve()
117 121
       })
118
-    },
122
+    }
119 123
     // 获取用户相关信息
120
-    getUserInfo ({ state, commit }) {
121
-      return new Promise((resolve, reject) => {
122
-        try {
123
-          getUserInfo(state.token).then(res => {
124
-            const data = res.data
125
-            // --------------------------------------------
126
-            // commit('setAvatar', data.avatar)
127
-            // commit('setUserName', data.name)
128
-            // commit('setUserId', data.user_id)
129
-            // commit('setAccess', data.access)
130
-            // commit('setHasGetInfo', true)
131
-            // ---------------------------------------------------
132
-            resolve(data)
133
-          }).catch(err => {
134
-            reject(err)
135
-          })
136
-        } catch (error) {
137
-          reject(error)
138
-        }
139
-      })
140
-    },
124
+    // getUserInfo ({ state, commit }) {
125
+    //   return new Promise((resolve, reject) => {
126
+    //     try {
127
+    //       getUserInfo(state.token).then(res => {
128
+    //         const data = res.data
129
+    // --------------------------------------------
130
+    // commit('setAvatar', data.avatar)
131
+    // commit('setUserName', data.name)
132
+    // commit('setUserId', data.user_id)
133
+    // commit('setAccess', data.access)
134
+    // commit('setHasGetInfo', true)
135
+    // ---------------------------------------------------
136
+    //         resolve(data)
137
+    //       }).catch(err => {
138
+    //         reject(err)
139
+    //       })
140
+    //     } catch (error) {
141
+    //       reject(error)
142
+    //     }
143
+    //   })
144
+    // },
141 145
     // 此方法用来获取未读消息条数,接口只返回数值,不返回消息列表
142
-    getUnreadMessageCount ({ state, commit }) {
143
-      getUnreadCount().then(res => {
144
-        const { data } = res
145
-        commit('setMessageCount', data)
146
-      })
147
-    },
146
+    // getUnreadMessageCount ({ state, commit }) {
147
+    //   getUnreadCount().then(res => {
148
+    //     const { data } = res
149
+    //     commit('setMessageCount', data)
150
+    //   })
151
+    // },
148 152
     // 获取消息列表,其中包含未读、已读、回收站三个列表
149
-    getMessageList ({ state, commit }) {
150
-      return new Promise((resolve, reject) => {
151
-        getMessage().then(res => {
152
-          const { unread, readed, trash } = res.data
153
-          commit('setMessageUnreadList', unread.sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
154
-          commit('setMessageReadedList', readed.map(_ => {
155
-            _.loading = false
156
-            return _
157
-          }).sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
158
-          commit('setMessageTrashList', trash.map(_ => {
159
-            _.loading = false
160
-            return _
161
-          }).sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
162
-          resolve()
163
-        }).catch(error => {
164
-          reject(error)
165
-        })
166
-      })
167
-    },
153
+    // getMessageList ({ state, commit }) {
154
+    //   return new Promise((resolve, reject) => {
155
+    //     getMessage().then(res => {
156
+    //       const { unread, readed, trash } = res.data
157
+    //       commit('setMessageUnreadList', unread.sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
158
+    //       commit('setMessageReadedList', readed.map(_ => {
159
+    //         _.loading = false
160
+    //         return _
161
+    //       }).sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
162
+    //       commit('setMessageTrashList', trash.map(_ => {
163
+    //         _.loading = false
164
+    //         return _
165
+    //       }).sort((a, b) => new Date(b.create_time) - new Date(a.create_time)))
166
+    //       resolve()
167
+    //     }).catch(error => {
168
+    //       reject(error)
169
+    //     })
170
+    //   })
171
+    // },
168 172
     // 根据当前点击的消息的id获取内容
169
-    getContentByMsgId ({ state, commit }, { msg_id }) {
170
-      return new Promise((resolve, reject) => {
171
-        let contentItem = state.messageContentStore[msg_id]
172
-        if (contentItem) {
173
-          resolve(contentItem)
174
-        } else {
175
-          getContentByMsgId(msg_id).then(res => {
176
-            const content = res.data
177
-            commit('updateMessageContentStore', { msg_id, content })
178
-            resolve(content)
179
-          })
180
-        }
181
-      })
182
-    },
173
+    // getContentByMsgId ({ state, commit }, { msg_id }) {
174
+    //   return new Promise((resolve, reject) => {
175
+    //     let contentItem = state.messageContentStore[msg_id]
176
+    //     if (contentItem) {
177
+    //       resolve(contentItem)
178
+    //     } else {
179
+    //       getContentByMsgId(msg_id).then(res => {
180
+    //         const content = res.data
181
+    //         commit('updateMessageContentStore', { msg_id, content })
182
+    //         resolve(content)
183
+    //       })
184
+    //     }
185
+    //   })
186
+    // },
183 187
     // 把一个未读消息标记为已读
184
-    hasRead ({ state, commit }, { msg_id }) {
185
-      return new Promise((resolve, reject) => {
186
-        hasRead(msg_id).then(() => {
187
-          commit('moveMsg', {
188
-            from: 'messageUnreadList',
189
-            to: 'messageReadedList',
190
-            msg_id
191
-          })
192
-          commit('setMessageCount', state.unreadCount - 1)
193
-          resolve()
194
-        }).catch(error => {
195
-          reject(error)
196
-        })
197
-      })
198
-    },
188
+    // hasRead ({ state, commit }, { msg_id }) {
189
+    //   return new Promise((resolve, reject) => {
190
+    //     hasRead(msg_id).then(() => {
191
+    //       commit('moveMsg', {
192
+    //         from: 'messageUnreadList',
193
+    //         to: 'messageReadedList',
194
+    //         msg_id
195
+    //       })
196
+    //       commit('setMessageCount', state.unreadCount - 1)
197
+    //       resolve()
198
+    //     }).catch(error => {
199
+    //       reject(error)
200
+    //     })
201
+    //   })
202
+    // },
199 203
     // 删除一个已读消息到回收站
200
-    removeReaded ({ commit }, { msg_id }) {
201
-      return new Promise((resolve, reject) => {
202
-        removeReaded(msg_id).then(() => {
203
-          commit('moveMsg', {
204
-            from: 'messageReadedList',
205
-            to: 'messageTrashList',
206
-            msg_id
207
-          })
208
-          resolve()
209
-        }).catch(error => {
210
-          reject(error)
211
-        })
212
-      })
213
-    },
204
+    // removeReaded ({ commit }, { msg_id }) {
205
+    //   return new Promise((resolve, reject) => {
206
+    //     removeReaded(msg_id).then(() => {
207
+    //       commit('moveMsg', {
208
+    //         from: 'messageReadedList',
209
+    //         to: 'messageTrashList',
210
+    //         msg_id
211
+    //       })
212
+    //       resolve()
213
+    //     }).catch(error => {
214
+    //       reject(error)
215
+    //     })
216
+    //   })
217
+    // },
214 218
     // 还原一个已删除消息到已读消息
215
-    restoreTrash ({ commit }, { msg_id }) {
216
-      return new Promise((resolve, reject) => {
217
-        restoreTrash(msg_id).then(() => {
218
-          commit('moveMsg', {
219
-            from: 'messageTrashList',
220
-            to: 'messageReadedList',
221
-            msg_id
222
-          })
223
-          resolve()
224
-        }).catch(error => {
225
-          reject(error)
226
-        })
227
-      })
228
-    }
219
+    // restoreTrash ({ commit }, { msg_id }) {
220
+    //   return new Promise((resolve, reject) => {
221
+    //     restoreTrash(msg_id).then(() => {
222
+    //       commit('moveMsg', {
223
+    //         from: 'messageTrashList',
224
+    //         to: 'messageReadedList',
225
+    //         msg_id
226
+    //       })
227
+    //       resolve()
228
+    //     }).catch(error => {
229
+    //       reject(error)
230
+    //     })
231
+    //   })
232
+    // }
229 233
   }
230 234
 }

+ 1
- 1
src/view/login/login.vue View File

@@ -39,7 +39,7 @@ export default {
39 39
       this.handleLogin({ loginname, loginpwd }).then(res => {
40 40
         // console.log(res)
41 41
         // initRouter()
42
-        console.log(this.$config.homeName)
42
+        // console.log(this.$config.homeName)
43 43
         this.$router.push({
44 44
           name: this.$config.homeName
45 45
         })

+ 196
- 86
src/view/manager/Information/index.vue View File

@@ -4,61 +4,68 @@
4 4
     <div class="infoContent">
5 5
        <i-form :model="form" :label-width="80">
6 6
           <Form-item label="标题">
7
-              <i-input v-model="formItem.title" placeholder="请输入资讯标题"></i-input>
7
+              <i-input v-model="form.ntitle" placeholder="请输入资讯标题"></i-input>
8 8
           </Form-item>
9
-          <Form-item label="分类" class="classify" prop='ntypename'>
10
-              <i-select v-model="form.ntypename" placeholder="请选择资讯分类">
11
-                  <i-option value="beijing">北京市</i-option>
12
-                  <i-option value="shanghai">上海市</i-option>
13
-                  <i-option value="shenzhen">深圳市</i-option>
9
+          <Form-item label="分类" class="classify" prop='ntypeid'>
10
+              <i-select v-model="form.ntypeid" placeholder="请选择资讯分类">
11
+                  <i-option v-for="item in classifyList" :key="item.ntypeid" :value="item.ntypeid">{{item.ntypename}}</i-option>
14 12
               </i-select>
15 13
           </Form-item>
16
-           <Form-item label="是否置顶" class="radio" prop='top'>
17
-              <Radio-group  v-model="formItem.top">
18
-                <Radio label='0'><span></span> </Radio>
19
-                <Radio   label='1'><span></span> </Radio>
14
+           <Form-item label="是否置顶"  class="radio" prop=' nistop'>
15
+              <Radio-group  v-model="form.nistop">
16
+                <Radio label='0'><span>不置顶</span> </Radio>
17
+                <Radio   label='1'><span>置顶</span> </Radio>
20 18
               </Radio-group>
21 19
           </Form-item>
22
-          <Form-item label="排序" class="radio" prop='ntypeorder'>
23
-               <div class="order">
24
-                  <i-button type='text'><i  class="ivu-icon ivu-icon- iconfont icon-21"></i></i-button>
25
-                   <i-input v-model="form.order" ></i-input>
26
-                  <i-button type='text'><i  class="ivu-icon ivu-icon- iconfont icon-jianhao"></i></i-button>
27
-               </div>
20
+          <Form-item  v-if="form.nistop==='1'" label="排序" class="radio radioOrder" prop=' norder'>
21
+               <!-- <div class="order"> -->
22
+                  <!-- <div class="btn" @click="calc(-1)"><i  class="ivu-icon ivu-icon- iconfont icon-jianhao"></i></div> -->
23
+            <i-input v-model="form.norder" style="text-align:center"  class="numInput">
24
+               <i-button slot="prepend" @click='calc(-1)' icon='ivu-icon ivu-icon- iconfont icon-jianhao' ></i-button>
25
+               <i-button slot="append" @click='calc(1)' icon='ivu-icon ivu-icon- iconfont  icon-21'></i-button>
26
+            </i-input>
27
+                  <!-- <div class="btn" @click="calc(1)"><i  class="ivu-icon ivu-icon- iconfont icon-21 "></i></div> -->
28
+               <!-- </div> -->
28 29
           </Form-item>
29
-          <Form-item label="是否广告位" class="radio" style="margin-left:30px">
30
-              <Radio-group :model.sync="formItem.adSlot">
31
-                <Radio value="0" label='否'></Radio>
32
-                <Radio value="1"  label='是'></Radio>
30
+          <Form-item label="是否广告位" class="radio" prop='nlevel'>
31
+              <Radio-group v-model="form.nlevel">
32
+                <Radio  label='0'>否</Radio>
33
+                <Radio   label='1'>是</Radio>
33 34
             </Radio-group>
34 35
           </Form-item>
35 36
           <Form-item label="标签" >
36
-              <i-input :value.sync="formItem.tag" placeholder="请输入标签"></i-input>
37
+            <i-select style="width:460px" :model.sync="form.ntagname" multiple @on-change="updatePermission" >
38
+                <i-option v-for="item in labelList" :key="item.ntagid" :value="item.ntagname" :label='item.ntagname'>{{ item.ntagname }}</i-option>
39
+            </i-select>
40
+              <!-- <i-input :value.sync="form.ntagname" placeholder="请输入标签"></i-input> -->
37 41
           </Form-item>
38 42
           <Form-item class="labelTop">
39
-            <p style="font-size:14px">资讯内容</p>
40
-            <editor ref="editor" :value="formItem.content" @on-change="handleChange"/>
43
+            <p style="font-size:12px">资讯内容</p>
44
+            <editor ref="editor" :value="form.ncontent" @on-change="handleChange"/>
41 45
           </Form-item>
42 46
           <Form-item class="imgVideo labelTop" >
43 47
             <p>封面图<span>(建议尺寸:840X400)</span></p>
44 48
             <div class="upload">
45
-                <Upload v-if="flag" ref="upload" :show-upload-list="false" :format="['jpg','jpeg','png']" :max-size="2048" :before-upload="handleBeforeUpload" :on-format-error="handleFormatError" :on-exceeded-size="handleMaxSize" type="drag" action="//jsonplaceholder.typicode.com/posts/" style="display: inline-block;width:58px;">
49
+                <Upload   ref="upload" :show-upload-list="false" :format="['jpg','jpeg','png']" :max-size="2048" :before-upload="handleBeforeUpload" :on-format-error="handleFormatError" :on-exceeded-size="handleMaxSize" type="drag" action=''>
46 50
                   <div style="width: 200px;height:200px;line-height: 200px;">
47
-                    <i  class="ivu-icon ivu-icon- iconfont icon-21"></i>
51
+                    <i style="color:#3D8EFE" class="ivu-icon ivu-icon- iconfont icon-21"></i>
48 52
                   </div>
49 53
                 </Upload>
50
-                 <img style="height:200px;width:200px" v-else :src="uploadImg" alt="">
54
+                 <img style="height:150px;width:150px" v-if="!flagImg" :src="imgCover" alt="">
51 55
             </div>
52 56
           </Form-item>
53 57
            <Form-item class="imgVideo" style="margin-left:200px">
54 58
              <p>视频</p>
55 59
             <div class="upload">
56
-                <Upload v-if="flag" ref="upload" :show-upload-list="false" :format="['jpg','jpeg','png']" :max-size="2048" :before-upload="handleBeforeUpload" :on-format-error="handleFormatError" :on-exceeded-size="handleMaxSize" type="drag" action="//jsonplaceholder.typicode.com/posts/" style="display: inline-block;width:58px;">
60
+                <Upload  ref="upload" :show-upload-list="false" :format="['mp4','avi',]" :max-size="2048" :before-upload="handleBeforeUpload2" :on-format-error="handleFormatError2" :on-exceeded-size="handleMaxSize2" type="drag" action=''>
57 61
                   <div style="width: 200px;height:200px;line-height: 200px;">
58
-                    <i  class="ivu-icon ivu-icon- iconfont icon-21"></i>
62
+                    <i  style="color:#3D8EFE" class="ivu-icon ivu-icon- iconfont icon-21"></i>
59 63
                   </div>
60 64
                 </Upload>
61
-                 <img style="height:200px;width:200px" v-else :src="uploadVideo" alt="">
65
+                    <div class="videoFile" v-if="!flagVideo" >
66
+                      <img src="../../../assets/img/video.png" alt="">
67
+                    <video style="height:200px;width:200px"  :src="form.nvideo" autoplay alt="" />
68
+                    </div>
62 69
             </div>
63 70
           </Form-item>
64 71
           <Form-item class="submitBtn">
@@ -71,10 +78,10 @@
71 78
 
72 79
 <script>
73 80
 import Editor from '_c/editor'
74
-import store from '@/store'
81
+// import store from '@/store'
75 82
 
76 83
 // import Cropper from '@/components/picture/index.vue'
77
-import { addInfo } from '@/api/info.js'
84
+import { addInfo, classify, tagList } from '@/api/info.js'
78 85
 
79 86
 export default {
80 87
   components: {
@@ -83,30 +90,62 @@ export default {
83 90
   },
84 91
   data () {
85 92
     return {
86
-      exampleImageSrc: '',
87
-      uploadImg: '',
88
-      flag: true,
93
+      classifyList: [],
94
+      imgCover: '',
95
+      labelList: [],
96
+      flagImg: true,
97
+      flagVideo: true,
98
+      userInfo: {},
89 99
       form: {
90
-        ntypename: '',
91
-        ntypeorder: 1,
92
-        createid: ''
93
-      },
94
-      formItem: {
95
-        title: '',
96
-        classify: '',
97
-        top: '0',
98
-        adSlot: '0',
99
-        tag: '',
100
-        content: ''
100
+        ntitle: '',
101
+        ncontent: '',
102
+        ncontxt: '',
103
+        ncover: '',
104
+        nvideo: '',
105
+        nvsize: '',
106
+        nvsuffix: '',
107
+        ntypeid: '',
108
+        norder: 1,
109
+        nistop: '0',
110
+        nlevel: '',
111
+        edid: '',
112
+        schoolid: '',
113
+        createid: '',
114
+        ntagname: undefined
101 115
       }
102 116
     }
103 117
   },
104 118
   mounted () {
105
-    // console.log(store.state.user.userInfo)
106
-    this.form.createid = store.state.user.userInfo.edid
119
+    this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
120
+    // console.log(this.userInfo.content)
121
+    this.form.schoolid = this.userInfo.content.schoolid
122
+    this.form.edid = this.userInfo.content.edid
123
+    this.form.nlevel = this.userInfo.content.schoolstate
124
+    this.form.createid = this.userInfo.content.userid
125
+    // console.log(this.form)
126
+    // 获取分类列表
127
+    classify().then(res => {
128
+      // console.log(res.data.obj)
129
+      this.classifyList = res.data.obj
130
+    })
131
+    // 获取标签;列表
132
+    tagList().then(res => {
133
+      // console.log(res.data.obj)
134
+
135
+      this.labelList = res.data.obj
136
+    })
107 137
   },
108 138
   methods: {
109
-    // ---------------------------------------------------------------
139
+    // 将标签内容格式化
140
+    updatePermission (e) {
141
+      // console.log(e)
142
+      this.form.ntagname = JSON.stringify({ ...e })
143
+    },
144
+    // 排序
145
+    calc (num) {
146
+      this.form.norder = Number(this.form.norder) + Number(num)
147
+    },
148
+    // 上传图片
110 149
     handleBeforeUpload (file) {
111 150
     // 创建一个 FileReader 对象
112 151
       let reader = new FileReader()
@@ -114,13 +153,15 @@ export default {
114 153
       // 当读操作完成,readyState 变为 DONE,loadend 被触发,此时 result 属性包含数据:URL(以 base64 编码的字符串表示文件的数据)
115 154
       // 读取文件作为 URL 可访问地址
116 155
       reader.readAsDataURL(file)
156
+      this.form.ncover = file.name
117 157
 
118 158
       const _this = this
119 159
       reader.onloadend = function (e) {
120 160
         file.url = reader.result
121
-        console.log(file.url)
122
-        _this.uploadImg = file.url
123
-        _this.flag = false
161
+        // console.log(file.url)
162
+        // console.log(_this.base64ToFile(file, file.url))
163
+        _this.imgCover = file.url
164
+        _this.flagImg = false
124 165
       }
125 166
     },
126 167
     handleFormatError (file) {
@@ -135,25 +176,56 @@ export default {
135 176
         desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
136 177
       })
137 178
     },
138
-    // ------------------------------------------------------------------
139
-    // handleImg (e) {
140
-    //   console.log(e)
141
-    // },
179
+    // 上传视频
180
+    handleBeforeUpload2 (file) {
181
+    // 创建一个 FileReader 对象
182
+      let reader = new FileReader()
183
+      // readAsDataURL 方法用于读取指定 Blob 或 File 的内容
184
+      // 当读操作完成,readyState 变为 DONE,loadend 被触发,此时 result 属性包含数据:URL(以 base64 编码的字符串表示文件的数据)
185
+      // 读取文件作为 URL 可访问地址
186
+      reader.readAsDataURL(file)
187
+      // console.log(file)
188
+      this.form.nvideo = file.name
189
+      this.form.nvsuffix = file.name.split('.')[1]
190
+      // console.log(this.form.nvsuffix[1])
191
+      const _this = this
192
+      reader.onloadend = function (e) {
193
+        file.url = reader.result
194
+        // console.log(file.url)
195
+        // _this.form.nvideo = file.url
196
+        // console.log(_this.extname(file))
197
+
198
+        var size = file.size
199
+        _this.form.nvsize = size
200
+        _this.flagVideo = false
201
+        _this.flag = false
202
+      }
203
+    },
204
+    handleFormatError2 (file) {
205
+      this.$Notice.warning({
206
+        title: '文件格式不正确',
207
+        desc: '文件 ' + file.name + ' 格式不正确,请上传 mp4 或 avi 格式的图片。'
208
+      })
209
+      this.flagVideo = true
210
+    },
211
+    handleMaxSize2 (file) {
212
+      this.$Notice.warning({
213
+        title: '超出文件大小限制',
214
+        desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
215
+      })
216
+    },
217
+    // 获取资讯内容
142 218
     handleChange (e) {
143 219
       console.log(e)
220
+      this.form.ncontent = e
221
+      this.form.ncontxt = e.replace(/<[^>]+>/g, '')
144 222
     },
223
+    // 添加
145 224
     submit () {
146 225
       console.log(this.form)
147
-      addInfo(this.formItem).then(res => {
226
+      addInfo(this.form).then(res => {
148 227
         console.log(res)
149 228
       })
150
-    },
151
-    handleCroped (blob) {
152
-      const formData = new FormData()
153
-      formData.append('croppedImg', blob)
154
-      uploadImg(formData).then(() => {
155
-        this.$Message.success('Upload success~')
156
-      })
157 229
     }
158 230
   }
159 231
 
@@ -172,46 +244,60 @@ export default {
172 244
     }
173 245
   }
174 246
   .infoContent{
175
-    padding: 20px 0 20px 10px;
247
+    padding: 20px 10px 20px 10px;
248
+    background: white;
249
+    .ivu-input-group .ivu-input, .ivu-input-group .ivu-input-inner-container {
250
+    width: 100%;
251
+    float: left;
252
+    margin-bottom: 0;
253
+    position: relative;
254
+    z-index: 2;
255
+    text-align: center;
256
+    display: flex;
257
+    justify-content: center;
258
+    align-items: center;
259
+}
260
+   .ivu-form .ivu-form-item-label {
261
+      font-size: 12px!important;
262
+    }
176 263
     .classify{
177 264
       display: inline-block;
178
-      width: 500px;
265
+      width: 300px;
179 266
     }
180 267
     .submitBtn{
181 268
       display: flex;
182 269
       justify-content: center;
183 270
       margin-top:60px;
184 271
     }
272
+    .radioOrder{
273
+      margin-left: -35px;
274
+      margin-right: 20px;
275
+    }
185 276
     .radio{
186 277
       display: inline-block;
187
-      .order{
188
-        border: 1px solid grey;
189
-        height: 32px;
190
-        .ivu-btn-text{
191
-          float: left;
192
-          width: 20px;
193
-          // border: 1px solid grey;
194
-          display: flex;
195
-          justify-content: center;
196
-          border-radius: none;
197
-        }
198
-        .ivu-input-wrapper-default{
199
-          width: 40px;
200
-          height: 32px;
201
-          float: left;
202
-          border-radius: none;
203
-        }
278
+      .ivu-input-group {
279
+        width: 110px;
204 280
       }
205
-
206
-    }
207
-    .ivu-form-item-label{
208
-      font-size: 14px!important;
281
+      .ivu-btn-icon-only{
282
+        height: 34px;
283
+        width: 30px;
284
+        display: flex;
285
+        justify-content: center;
286
+        align-items: center;
287
+        // line-height: 20px;
288
+      }
289
+      // .ivu-input {
290
+      //   height: 35px;
291
+      //   width: 80px!important;
292
+      // }
209 293
     }
294
+
210 295
     .labelTop{
211 296
       margin-left: -40px;
212 297
     }
213 298
     .imgVideo{
214 299
       display: inline-block;
300
+      position: relative;
215 301
       p{
216 302
         font-size: 16px;
217 303
         span{
@@ -220,6 +306,13 @@ export default {
220 306
           color: #3D8EFE;
221 307
         }
222 308
       }
309
+      img{
310
+        position: absolute;
311
+        top: 60px;
312
+        left: 25px;
313
+        z-index: 999;
314
+
315
+      }
223 316
     }
224 317
     .upload{
225 318
       height: 200px;
@@ -242,6 +335,23 @@ export default {
242 335
       .icon-21:before {
243 336
         font-size: 40px;
244 337
       }
338
+      .videoFile{
339
+        // border: 1px solid grey;
340
+         height: 200px;
341
+        width: 200px;
342
+        position: relative;
343
+           img{
344
+        height: 120px;
345
+        position: absolute;
346
+        top: -200px;
347
+        left: -55px;
348
+        width: 150px;
349
+        margin-left: 80px;
350
+        margin-top: 40px;
351
+        z-index: 999;
352
+        }
353
+
354
+      }
245 355
     }
246 356
 
247 357
   }

Loading…
Cancel
Save