zxl
3 天以前 934654b44fb2670a7ce08aafa3d1d85fe783ae26
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<template>
  <div>
    <BaseHeader></BaseHeader>
    <Search></Search>
 
    <div class="title-bg"><p>文章帮助中心</p></div>
    <div class="container width_1200">
      <Layout class="layoutAll">
        <Sider class="side-bar" ref="side" :collapsed-width="78">
          <div class="article-cate">文章分类列表</div>
          <Menu
            class="side-menu"
            theme="light"
            width="auto"
            ref='menu'
            :active-name="activeName"
            :open-names="openName"
            @on-select="onSelect"
          >
            <!-- 循环导航栏  -->
            <Submenu
              v-show="menu.children"
              v-for="(menu, index) in list"
              :key="index"
              :name="menu.articleCategoryName"
            >
              <template slot="title">
                <span>{{ menu.articleCategoryName }}</span>
              </template>
              <MenuItem
                v-for="(chlidren, i) in menu.children"
                :key="i"
                :name="chlidren.id"
                >{{ chlidren.articleCategoryName }}</MenuItem
              >
            </Submenu>
          </Menu>
        </Sider>
        <Layout class="layout ml_10">
          <Content class="content">
            <ul class="article-list" v-show="showList">
              <li v-for="(article, index) in articleList" :key="index" @click="getDetail(article.id)">
                {{article.title}}
              </li>
            </ul>
            <transition mode="out-in">
              <div v-show="!showList">
                <a class="back-btn" @click="showList = true">&lt;返回上一级</a>
                <h2 class="mt_10 mb_10">{{detail.title}}</h2>
                <div class="mt_10 mb_10" v-html="detail.content"></div>
              </div>
            </transition>
          </Content>
        </Layout>
      </Layout>
    </div>
  </div>
</template>
 
<script>
import {articleCateList, articleDetail, articleList} from '@/api/common.js'
export default {
  name: 'Home',
  data () {
    return {
      list: [], // 分类列表
      detail: '', // 文章详情
      articleList: [], // 分类下的文章列表
      activeName: '1347456734864367616', // 左侧激活项
      openName: [], // 展开的名称
      params: { // 请求参数
        pageNumber: 1,
        pageSize: 100,
        categoryId: '',
        sort: 'sort'
      },
      showList: true // 展示文章列表
    };
  },
  methods: {
    // 每次点击左侧bar的callback
    onSelect (id) {
      this.getList(id)
      this.detail = ''
      this.showList = true
    },
    getCateList () { // 文章分类列表
      articleCateList().then(res => {
        if (res.success) {
          this.list = res.result
          if (this.$route.query.id) {
            this.activeName = this.detail.categoryId
            this.list.forEach(e => {
              if (e.children.length) {
                e.children.forEach(i => {
                  if (i.id === this.detail.categoryId) {
                    this.openName.push(e.articleCategoryName)
                  }
                })
              } else {
                delete e.children
              }
            })
          } else {
            this.activeName = this.list[0].children[0].id
            this.openName.push(this.list[0].articleCategoryName)
          }
          this.$nextTick(() => {
            this.$refs.menu.updateOpened()
            this.$refs.menu.updateActiveName()
          })
          this.getList(this.activeName)
        }
      })
    },
    getList (id) { // 文章列表
      this.params.categoryId = id
      articleList(this.params).then(res => {
        if (res.success) {
          this.articleList = res.result.records
        }
      })
    },
    async getDetail (id) { // 文章详情
      await articleDetail(id).then(res => {
        if (res.success) {
          this.detail = res.result
          this.showList = false
        }
      })
    }
  },
  async mounted () {
    const articleId = this.$route.query.id
    if (articleId) {
      await this.getDetail(articleId)
    }
    this.getCateList()
  }
};
</script>
 
<style scoped lang="scss">
.content {
  padding: 15px 50px;
}
 
.header {
  @include background_color($light_background_color);
}
 
.side-menu,
.side-bar,
.content {
  @include white_background_color();
  @include title_color($light_title_color);
}
 
.side-bar {
  min-height: 600px;
  height: auto;
}
 
.layoutAll {
  min-height: 1200px;
  @include background_color($light_background_color);
}
 
.container {
  margin: 0 auto;
  padding: 20px 0;
}
 
.side-bar a {
  @include title_color($light_title_color);
}
 
.layout-footer-center {
  padding: 0px 15px;
 
  padding-bottom: 15px;
  text-align: center;
}
.title-bg{
  height: 100px;
  width: 100%;
  background-color: #7b7b7b;
  p{
    width: 1200px;
    font-size: 30px;
    height: 100px;
    line-height: 100px;
    color: #fff;
    line-height: 100px;
    margin: 0 auto;
    padding-left: 10px;
  }
}
.article-cate{
  width: 200px;
  height: 30px;
  color: #fff;
  line-height: 30px;
  text-align: center;
  font-size: 18px;
  background-color: #666;
}
.article-list {
  li{
    margin: 10px 0;
    color: #2D8CF0;
    &:hover{
      cursor: pointer;
    }
  }
}
</style>