티스토리 뷰

3. 스크립트

(타슈켄트) 뷰> 중고차플젝 user.js magazine.js

패스트코드블로그 2020. 5. 28. 09:28

user.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import axios from 'axios'
import router from '@/router'
 
const state = {
    context : 'http://localhost:8080/',
    user : {},
    auth: false,
    fail: false
}
const getters = {
    getMember : state=>state.user,
    getIsAuth : state=>state.auth,
    getFail : state=> state.fail
}
 
const actions = {
    async login({commit}, loginData ){
      const url = state.context + 'login'
      const headers ={  'authorization''JWT fefege..',
            'Accept' : 'application/json',
            'Content-Type''application/json'}
        axios.post(url, loginData , headers )
            .then(({data})=>{
                if(data.result) {
                    commit('LOGIN_COMMIT', data)
                }else{
                    commit('fail_commit')
                }
            })
            .catch(()=>{
                state.fail = true
            })
    },
    async logout({commit}){
        commit('LOGOUT_COMMIT')
    },
    async getUserInfo({commit}){
        const url = state.context + 'getUserInfo'
        const token = localStorage.getItem("token")
        const headers = {headers : {
                'Accept' : 'application/json',
            }}
        axios.post(url,token,headers)
            .then(({data})=>{
                if(data.result){
                    commit('REFRESH', data)
                }else{
                    commit('LOGOUT_COMMIT')
                    alert(`토큰이 만료되었습니다.\n 로그인을 다시 해주세요!`)
                    router.push('/login')
                }
            })
    },
    async loginDestory({commit}){
        commit('LOGINDESTROY')
    }
}
const mutations = {
    LOGIN_COMMIT(state, data){
        state.auth = true
        state.user = data.user
        localStorage.setItem("token", data.token)
        localStorage.setItem("userId",data.user.userid)
        if(data.user.auth==="USER") {
            router.push('/home')
        }else{
            router.push('/companyHome')
        }
    },
    REFRESH(state, data){
        state.auth = true
        state.user = data.user
        localStorage.setItem("token", data.token)
        localStorage.setItem("userId",data.user.userid)
        router.go(1)
    },
 
    LOGOUT_COMMIT(state){
        localStorage.clear()
        state.auth = false
        state.user  = {}
    },
    fail_commit(state){
        state.fail = true
    },
    LOGINDESTROY(state){
        state.fail = false
    }
}
export default {
    name: 'user',
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
cs

magazine.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import axios from "axios";
 
const state = {
  context : 'http://localhost:8080/',
  wordList : [],
  originWordList : '',
  carsList : '',
  articleList : ''
}
const getters = {
    wordList : state => state.wordList,
    carsList : state => state.carsList,
    articleList : state => state.articleList
}
const actions = {
    async getExtractWord({ commit } ){
      const url = state.context + 'magazine/init'
        axios
            .get(url)
            .then(({data})=>{
                commit('GETEXTRACTEDWORD', data )})
            .catch(()=>{
                alert('잘못된 요청입니다.')
            })
    },
    async aiEditor({ commit } , keyWord ){
      let url = state.context + 'magazine/AIEditer/'+keyWord
        axios
            .get(url)
            .then(({data})=>{
                commit('AIEDITOR', data )})
            .catch(()=>{
                alert('잘못된 요청입니다.')
            })
    },
    async getSelectedWord({ commit } , targetitem ){
        commit('GETSELECTEDWORD', targetitem )
    }
}
const mutations = {
    GETEXTRACTEDWORD ( state , data ) {
        state.wordList = []
        data.extractedWordList.forEach( item => {
            state.wordList.push([item.word , item.count]);
        })
    },
    GETSELECTEDWORD ( state , targetitem ) {
        state.originWordList = state.wordList
        state.wordList = []
        state.wordList.push(targetitem)
    },
    AIEDITOR ( state , data ) {
        state.carsList = []
        state.articleList = []
        state.carsList = data.carsList
        state.articleList = data.articles
    }
}
export default {
    name: 'magazine',
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
cs

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함