refine code
This commit is contained in:
		@@ -48,8 +48,11 @@ export default [
 | 
				
			|||||||
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
 | 
					      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        total: mockList.length,
 | 
					        code: '20000',
 | 
				
			||||||
        items: pageList
 | 
					        data: {
 | 
				
			||||||
 | 
					          total: mockList.length,
 | 
				
			||||||
 | 
					          items: pageList
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
@@ -61,7 +64,10 @@ export default [
 | 
				
			|||||||
      const { id } = config.query
 | 
					      const { id } = config.query
 | 
				
			||||||
      for (const article of List) {
 | 
					      for (const article of List) {
 | 
				
			||||||
        if (article.id === +id) {
 | 
					        if (article.id === +id) {
 | 
				
			||||||
          return article
 | 
					          return {
 | 
				
			||||||
 | 
					            code: '20000',
 | 
				
			||||||
 | 
					            data: article
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -71,12 +77,16 @@ export default [
 | 
				
			|||||||
    url: '/article/pv',
 | 
					    url: '/article/pv',
 | 
				
			||||||
    type: 'get',
 | 
					    type: 'get',
 | 
				
			||||||
    response: _ => {
 | 
					    response: _ => {
 | 
				
			||||||
      return { pvData: [
 | 
					      return {
 | 
				
			||||||
        { key: 'PC', pv: 1024 },
 | 
					        code: '20000',
 | 
				
			||||||
        { key: 'mobile', pv: 1024 },
 | 
					        data: {
 | 
				
			||||||
        { key: 'ios', pv: 1024 },
 | 
					          pvData: [
 | 
				
			||||||
        { key: 'android', pv: 1024 }
 | 
					            { key: 'PC', pv: 1024 },
 | 
				
			||||||
      ]
 | 
					            { key: 'mobile', pv: 1024 },
 | 
				
			||||||
 | 
					            { key: 'ios', pv: 1024 },
 | 
				
			||||||
 | 
					            { key: 'android', pv: 1024 }
 | 
				
			||||||
 | 
					          ]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
@@ -86,6 +96,7 @@ export default [
 | 
				
			|||||||
    type: 'post',
 | 
					    type: 'post',
 | 
				
			||||||
    response: _ => {
 | 
					    response: _ => {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
        data: 'success'
 | 
					        data: 'success'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -96,6 +107,7 @@ export default [
 | 
				
			|||||||
    type: 'post',
 | 
					    type: 'post',
 | 
				
			||||||
    response: _ => {
 | 
					    response: _ => {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
        data: 'success'
 | 
					        data: 'success'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,10 @@ export default [
 | 
				
			|||||||
        const lowerCaseName = item.name.toLowerCase()
 | 
					        const lowerCaseName = item.name.toLowerCase()
 | 
				
			||||||
        return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
 | 
					        return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      return { items: mockNameList }
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
 | 
					        data: { items: mockNameList }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,14 +34,17 @@ export default [
 | 
				
			|||||||
    type: 'get',
 | 
					    type: 'get',
 | 
				
			||||||
    response: _ => {
 | 
					    response: _ => {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        total: 20,
 | 
					        code: '20000',
 | 
				
			||||||
        'items|20': [{
 | 
					        data: {
 | 
				
			||||||
          order_no: '@guid()',
 | 
					          total: 20,
 | 
				
			||||||
          timestamp: +Mock.Random.date('T'),
 | 
					          'items|20': [{
 | 
				
			||||||
          username: '@name()',
 | 
					            order_no: '@guid()',
 | 
				
			||||||
          price: '@float(1000, 15000, 0, 2)',
 | 
					            timestamp: +Mock.Random.date('T'),
 | 
				
			||||||
          'status|1': ['success', 'pending']
 | 
					            username: '@name()',
 | 
				
			||||||
        }]
 | 
					            price: '@float(1000, 15000, 0, 2)',
 | 
				
			||||||
 | 
					            'status|1': ['success', 'pending']
 | 
				
			||||||
 | 
					          }]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								mock/user.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								mock/user.js
									
									
									
									
									
								
							@@ -30,7 +30,10 @@ export default [
 | 
				
			|||||||
    type: 'post',
 | 
					    type: 'post',
 | 
				
			||||||
    response: config => {
 | 
					    response: config => {
 | 
				
			||||||
      const { username } = config.body
 | 
					      const { username } = config.body
 | 
				
			||||||
      return tokens[username]
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
 | 
					        data: tokens[username]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,7 +43,10 @@ export default [
 | 
				
			|||||||
    type: 'get',
 | 
					    type: 'get',
 | 
				
			||||||
    response: config => {
 | 
					    response: config => {
 | 
				
			||||||
      const { token } = config.query
 | 
					      const { token } = config.query
 | 
				
			||||||
      return users[token]
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
 | 
					        data: users[token]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -50,6 +56,7 @@ export default [
 | 
				
			|||||||
    type: 'post',
 | 
					    type: 'post',
 | 
				
			||||||
    response: _ => {
 | 
					    response: _ => {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
 | 
					        code: '20000',
 | 
				
			||||||
        data: 'success'
 | 
					        data: 'success'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,10 +77,10 @@ export default {
 | 
				
			|||||||
    toggleSideBar() {
 | 
					    toggleSideBar() {
 | 
				
			||||||
      this.$store.dispatch('toggleSideBar')
 | 
					      this.$store.dispatch('toggleSideBar')
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    logout() {
 | 
					    async logout() {
 | 
				
			||||||
      this.$store.dispatch('Logout').then(() => {
 | 
					      await this.$store.dispatch('Logout')
 | 
				
			||||||
        location.reload()// In order to re-instantiate the vue-router object to avoid bugs
 | 
					      // In order to re-instantiate the vue-router object to avoid bugs
 | 
				
			||||||
      })
 | 
					      location.reload()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ const user = {
 | 
				
			|||||||
        login({ username: username.trim(), password: password }).then(response => {
 | 
					        login({ username: username.trim(), password: password }).then(response => {
 | 
				
			||||||
          const { data } = response
 | 
					          const { data } = response
 | 
				
			||||||
          commit('SET_TOKEN', data.token)
 | 
					          commit('SET_TOKEN', data.token)
 | 
				
			||||||
          setToken(response.data.token)
 | 
					          setToken(data.token)
 | 
				
			||||||
          resolve()
 | 
					          resolve()
 | 
				
			||||||
        }).catch(error => {
 | 
					        }).catch(error => {
 | 
				
			||||||
          reject(error)
 | 
					          reject(error)
 | 
				
			||||||
@@ -54,17 +54,17 @@ const user = {
 | 
				
			|||||||
            reject('Verification failed, please Login again.')
 | 
					            reject('Verification failed, please Login again.')
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const { roles } = data
 | 
					          const { roles, name, avatar, introduction } = data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // roles must be a non-empty array
 | 
					          // roles must be a non-empty array
 | 
				
			||||||
          if (!roles || roles.length <= 0) {
 | 
					          if (!roles || roles.length <= 0) {
 | 
				
			||||||
            reject('getInfo: roles must be a non-null array!')
 | 
					            reject('getInfo: roles must be a non-null array!')
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          commit('SET_ROLES', data.roles)
 | 
					          commit('SET_ROLES', roles)
 | 
				
			||||||
          commit('SET_NAME', data.name)
 | 
					          commit('SET_NAME', name)
 | 
				
			||||||
          commit('SET_AVATAR', data.avatar)
 | 
					          commit('SET_AVATAR', avatar)
 | 
				
			||||||
          commit('SET_INTRODUCTION', data.introduction)
 | 
					          commit('SET_INTRODUCTION', introduction)
 | 
				
			||||||
          resolve(data)
 | 
					          resolve(data)
 | 
				
			||||||
        }).catch(error => {
 | 
					        }).catch(error => {
 | 
				
			||||||
          reject(error)
 | 
					          reject(error)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,11 @@ service.interceptors.request.use(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// response interceptor
 | 
					// response interceptor
 | 
				
			||||||
service.interceptors.response.use(
 | 
					service.interceptors.response.use(
 | 
				
			||||||
  response => response,
 | 
					  /**
 | 
				
			||||||
 | 
					   * If you want to get information such as headers or status
 | 
				
			||||||
 | 
					   * Please return  response => response
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					  response => response.data,
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * 下面的注释为通过在response里,自定义code来标示请求状态
 | 
					   * 下面的注释为通过在response里,自定义code来标示请求状态
 | 
				
			||||||
   * 当code返回如下情况则说明权限有问题,登出并返回到登录页
 | 
					   * 当code返回如下情况则说明权限有问题,登出并返回到登录页
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -96,17 +96,16 @@ export default {
 | 
				
			|||||||
    this.getList()
 | 
					    this.getList()
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    getList() {
 | 
					    async getList() {
 | 
				
			||||||
      this.listLoading = true
 | 
					      this.listLoading = true
 | 
				
			||||||
      fetchList(this.listQuery).then(response => {
 | 
					      const { data } = await fetchList(this.listQuery)
 | 
				
			||||||
        this.list = response.data.items
 | 
					      this.list = data.items
 | 
				
			||||||
        this.total = response.data.total
 | 
					      this.total = data.total
 | 
				
			||||||
        this.listLoading = false
 | 
					      this.listLoading = false
 | 
				
			||||||
        this.oldList = this.list.map(v => v.id)
 | 
					      this.oldList = this.list.map(v => v.id)
 | 
				
			||||||
        this.newList = this.oldList.slice()
 | 
					      this.newList = this.oldList.slice()
 | 
				
			||||||
        this.$nextTick(() => {
 | 
					      this.$nextTick(() => {
 | 
				
			||||||
          this.setSort()
 | 
					        this.setSort()
 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    setSort() {
 | 
					    setSort() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,17 +88,16 @@ export default {
 | 
				
			|||||||
    this.getList()
 | 
					    this.getList()
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    getList() {
 | 
					    async getList() {
 | 
				
			||||||
      this.listLoading = true
 | 
					      this.listLoading = true
 | 
				
			||||||
      fetchList(this.listQuery).then(response => {
 | 
					      const { data } = await fetchList(this.listQuery)
 | 
				
			||||||
        const items = response.data.items
 | 
					      const items = data.items
 | 
				
			||||||
        this.list = items.map(v => {
 | 
					      this.list = items.map(v => {
 | 
				
			||||||
          this.$set(v, 'edit', false) // https://vuejs.org/v2/guide/reactivity.html
 | 
					        this.$set(v, 'edit', false) // https://vuejs.org/v2/guide/reactivity.html
 | 
				
			||||||
          v.originalTitle = v.title //  will be used when user click the cancel botton
 | 
					        v.originalTitle = v.title //  will be used when user click the cancel botton
 | 
				
			||||||
          return v
 | 
					        return v
 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        this.listLoading = false
 | 
					 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					      this.listLoading = false
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    cancelEdit(row) {
 | 
					    cancelEdit(row) {
 | 
				
			||||||
      row.title = row.originalTitle
 | 
					      row.title = row.originalTitle
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,12 +53,11 @@ export default {
 | 
				
			|||||||
    this.fetchData()
 | 
					    this.fetchData()
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    fetchData() {
 | 
					    async fetchData() {
 | 
				
			||||||
      this.listLoading = true
 | 
					      this.listLoading = true
 | 
				
			||||||
      fetchList().then(response => {
 | 
					      const { data } = await fetchList()
 | 
				
			||||||
        this.list = response.data.items
 | 
					      this.list = data.items
 | 
				
			||||||
        this.listLoading = false
 | 
					      this.listLoading = false
 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    handleDownload() {
 | 
					    handleDownload() {
 | 
				
			||||||
      this.downloadLoading = true
 | 
					      this.downloadLoading = true
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user