Skip to content

Commit 8a1dc20

Browse files
committed
fix:vuet
1 parent 4557be7 commit 8a1dc20

File tree

13 files changed

+427
-448
lines changed

13 files changed

+427
-448
lines changed

package-lock.json

+209-210
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
"normalize.css": "^5.0.0",
5858
"vue": "^2.3.4",
5959
"vue-router": "^2.5.3",
60-
"vuet": "^0.2.7",
60+
"vuet": "^1.0.0-rc.3",
61+
"vuet-route": "0.0.8",
62+
"vuet-scroll": "0.0.2",
6163
"whatwg-fetch": "^2.0.3"
6264
}
6365
}

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import './less/common.less'
77

88
import Vue from 'vue'
99

10+
import vuet from './vuet/' // 注意:Vuet要在所有组件初始化前执行,避免第三方插件无法使用
1011
import router from './router/'
11-
import vuet from './vuet/'
1212
import * as filters from './filters/'
1313
import components from './components/'
1414

src/pages/index/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</nav>
1111
<v-content v-vuet-scroll="{ path: 'topic-list', name: 'content' }">
1212
<ul class="list">
13-
<li v-for="item in list.data" key="item.id">
13+
<li v-for="item in data.list" key="item.id">
1414
<router-link :to="{ name: 'topic-detail', params: { id: item.id } }">
1515
<div class="top" flex="box:first">
1616
<div class="headimg" :style="{ backgroundImage: 'url(' + item.author.avatar_url + ')' }"></div>
@@ -47,7 +47,7 @@
4747
</router-link>
4848
</li>
4949
</ul>
50-
<v-loading :done="list.done" :loading="list.loading" @seeing="$vuet.fetch('topic-list')"></v-loading>
50+
<v-loading :done="data.done" :loading="data.loading" @seeing="data.fetch()"></v-loading>
5151
</v-content>
5252
<v-footer></v-footer>
5353
</div>
@@ -57,7 +57,7 @@
5757
5858
export default {
5959
mixins: [
60-
mapModules({ list: 'topic-list' }),
60+
mapModules({ data: 'topic-list' }),
6161
mapRules({ route: 'topic-list' })
6262
],
6363
data () {

src/pages/self/home/index.vue

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<div>
33
<v-header title="个人中心">
4-
<div slot="right" class="item" flex="main:center cross:center" v-if="data.id" v-on:click="$router.push('/signout')">
4+
<div slot="right" class="item" flex="main:center cross:center" v-if="self.id" v-on:click="$router.push('/signout')">
55
<i class="iconfont icon-signout"></i>
66
</div>
77
</v-header>
88
<v-content v-vuet-scroll="{ path: 'user-self', name: 'content' }">
9-
<router-link v-if="data.avatar_url" :to="{ name: 'user-detail', params: { username: data.loginname } }">
9+
<router-link v-if="self.avatar_url" :to="{ name: 'user-detail', params: { username: self.loginname } }">
1010
<div class="user"></div>
11-
<div class="headimg" :style="{backgroundImage: 'url(' + data.avatar_url + ')'}"></div>
12-
<div class="user-name">{{ data.loginname }}</div>
11+
<div class="headimg" :style="{backgroundImage: 'url(' + self.avatar_url + ')'}"></div>
12+
<div class="user-name">{{ self.loginname }}</div>
1313
</router-link>
14-
<router-link v-if="!data.avatar_url" :to="{ name: 'signin' }">
14+
<router-link v-if="!self.avatar_url" :to="{ name: 'signin' }">
1515
<div class="user"></div>
1616
<div class="headimg"></div>
1717
<div class="user-name">你还未登录,请先登录!</div>
@@ -65,12 +65,7 @@
6565
export default {
6666
mixins: [
6767
mapModules({ self: 'user-self' })
68-
],
69-
computed: {
70-
data () {
71-
return this.self.data
72-
}
73-
}
68+
]
7469
}
7570
7671
</script>

src/pages/self/messages/index.vue

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<div>
33
<v-header title="消息"></v-header>
44
<v-content v-vuet-scroll="{ path: 'user-messages', name: 'content' }">
5-
<div class="msg-box" v-if="list.length">
5+
<div class="msg-box" v-if="messages.list.length">
66
<ul class="list">
7-
<li flex="box:first" v-for="(item, $index) in list">
7+
<li flex="box:first" v-for="(item, $index) in messages.list">
88
<router-link class="user" :to="{ name: 'user-detail',params: { username: item.author.loginname } }">
99
<div class="user-headimg" :style="{ backgroundImage: 'url(' + item.author.avatar_url +')' }"></div>
1010
</router-link>
@@ -29,7 +29,7 @@
2929
</li>
3030
</ul>
3131
</div>
32-
<v-data-null v-if="!list.length"></v-data-null>
32+
<v-data-null v-if="!messages.list.length"></v-data-null>
3333
</v-content>
3434
<v-footer></v-footer>
3535
</div>
@@ -41,15 +41,7 @@
4141
mixins: [
4242
mapModules({ self: 'user-self', messages: 'user-messages' }),
4343
mapRules({ need: 'user-messages' })
44-
],
45-
computed: {
46-
list () {
47-
return [...this.messages.data.has_read_messages, ...this.messages.data.hasnot_read_messages]
48-
},
49-
user () {
50-
return this.self.data
51-
}
52-
}
44+
]
5345
}
5446
5547
</script>

src/pages/signin/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
<script>
2121
import utils from 'utils'
2222
import is from 'is'
23-
import { mapRules } from 'vuet'
23+
import { mapModules } from 'vuet'
2424
2525
export default {
2626
mixins: [
27-
mapRules({ manual: 'user-self' })
27+
mapModules({ self: 'user-self' })
2828
],
2929
data () {
3030
return {
@@ -40,7 +40,7 @@
4040
if (!this.form.accesstoken) return utils.toast('请输入accesstoken')
4141
this.status = true
4242
try {
43-
const res = await this.$self.login(this.form.accesstoken)
43+
const res = await this.self.login(this.form.accesstoken)
4444
if (is.object(res)) {
4545
if (res.success) {
4646
utils.toast('登录成功')

src/pages/signout/index.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
</template>
44
<script>
55
6-
import { mapRules } from 'vuet'
6+
import { mapModules } from 'vuet'
77
88
export default {
99
mixins: [
10-
mapRules({ manual: 'user-self' })
10+
mapModules({ self: 'user-self' })
1111
],
1212
mounted () {
13-
this.$self.signout()
14-
this.$router.replace('/')
13+
this.self.signout()
1514
}
1615
}
1716

src/pages/topic/create/index.vue

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
22
<div>
33
<v-header title="发表">
4-
<a class="item" flex="main:center cross:center" slot="right" @click="submit">
4+
<a class="item" flex="main:center cross:center" slot="right" @click="form.create()">
55
<i class="iconfont icon-edit"></i>
66
</a>
77
</v-header>
88
<v-content>
9-
<form flex="dir:top" @submit.prevent="submit">
9+
<form flex="dir:top" @submit.prevent="form.create()">
1010
<div class="title">
1111
<input type="text" placeholder="标题..." v-model="form.title">
1212
</div>
@@ -28,23 +28,22 @@
2828
</div>
2929
</template>
3030
<script>
31-
import { mapModules, mapRules } from 'vuet'
31+
import { mapModules } from 'vuet'
3232
3333
export default {
3434
mixins: [
35-
mapModules({ form: 'topic-create' }),
36-
mapRules({ manual: 'topic-create' })
37-
],
38-
methods: {
39-
async submit () {
40-
const res = await this.$create.create()
41-
if (res.success) {
42-
this.$router.push({
43-
path: `/topic/${res.topic_id}`
44-
})
45-
}
46-
}
47-
}
35+
mapModules({ form: 'topic-create' })
36+
]
37+
// methods: {
38+
// async submit () {
39+
// const res = await this.form.create()
40+
// if (res && res.success) {
41+
// this.$router.push({
42+
// path: `/topic/${res.topic_id}`
43+
// })
44+
// }
45+
// }
46+
// }
4847
}
4948
5049
</script>

src/pages/topic/detail/index.vue

+32-27
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
</div>
77
</v-header>
88
<v-content style="bottom: 0;" v-vuet-scroll="{ path: 'topic-detail', name: 'content' }">
9-
<v-loading v-if="detail.loading"></v-loading>
10-
<v-data-null v-if="!detail.existence" msg="话题不存在"></v-data-null>
11-
<template v-if="!detail.loading && detail.existence">
12-
<div class="common-typeicon" flex v-if="data.top || data.good">
13-
<div class="icon" v-if="data.good">
9+
<v-loading v-if="data.loading"></v-loading>
10+
<v-data-null v-if="!data.existence" msg="话题不存在"></v-data-null>
11+
<template v-if="!data.loading && data.existence">
12+
<div class="common-typeicon" flex v-if="topic.top || topic.good">
13+
<div class="icon" v-if="topic.good">
1414
<i class="iconfont icon-topic-good"></i>
1515
</div>
16-
<div class="icon" v-if="data.top">
16+
<div class="icon" v-if="topic.top">
1717
<i class="iconfont icon-topic-top"></i>
1818
</div>
1919
</div>
@@ -27,7 +27,7 @@
2727
<div class="bd">
2828
<div flex>
2929
<router-link flex-box="0" :to="{ name: 'user-detail', params: { username: author.loginname } }">{{ author.loginname }}</router-link>
30-
<time flex-box="1">{{ data.create_at | formatDate }}</time>
30+
<time flex-box="1">{{ topic.create_at | formatDate }}</time>
3131
<div flex-box="0" class="num">#楼主</div>
3232
</div>
3333
</div>
@@ -36,19 +36,19 @@
3636
<!-- 主题信息 start -->
3737
<li>
3838
<div class="datas">
39-
<div class="tit">{{ data.title }}</div>
39+
<div class="tit">{{ topic.title }}</div>
4040
<div class="bottom" flex="main:center">
4141
<div class="item click" flex="main:center cross:center">
4242
<i class="iconfont icon-click"></i>
43-
<div class="num">{{ data.visit_count }}</div>
43+
<div class="num">{{ topic.visit_count }}</div>
4444
</div>
4545
<div class="item reply" flex="main:center cross:center">
4646
<i class="iconfont icon-comment"></i>
47-
<div class="num">{{ data.reply_count }}</div>
47+
<div class="num">{{ topic.reply_count }}</div>
4848
</div>
4949
</div>
5050
</div>
51-
<div class="markdown-body" v-html="data.content"></div>
51+
<div class="markdown-body" v-html="topic.content"></div>
5252
</li>
5353
<!-- 主题信息 end -->
5454
<li class="replies-count" v-if="replies.length">
@@ -71,21 +71,26 @@
7171
<div class="icon" @click="commentShow(item, $index)">
7272
<i class="iconfont icon-comment-topic"></i>
7373
</div>
74-
<div class="icon" :class="{ fabulous: testThing(item.ups) }" v-if="item.author.loginname !== user.data.loginname" @click="fabulousItem(item)">
74+
<div class="icon" :class="{ fabulous: testThing(item.ups) }" v-if="item.author.loginname !== self.loginname" @click="fabulousItem(item)">
7575
<i class="iconfont icon-comment-fabulous"></i>
7676
<em v-if="item.ups.length">{{ item.ups.length }}</em>
7777
</div>
7878
</div>
7979
</div>
8080
</div>
81-
<reply-box v-if="detail.commentId === item.id" :loginname="item.author.loginname" :replyId="item.id"></reply-box>
81+
<reply-box
82+
v-if="data.commentId === item.id"
83+
:loginname="item.author.loginname"
84+
:replyId="item.id"
85+
@success="data.fetch()"
86+
></reply-box>
8287
</li>
8388
<!-- 主题评论 end -->
8489
</ul>
85-
<div class="reply" v-if="user.data.id">
86-
<reply-box @success="$vuet.fetch('topic-detail')"></reply-box>
90+
<div class="reply" v-if="self.id">
91+
<reply-box @success="data.fetch()"></reply-box>
8792
</div>
88-
<div class="tip-login" v-if="!user.data.id">
93+
<div class="tip-login" v-if="!self.id">
8994
你还未登录,请先
9095
<router-link to="/login">登录</router-link>
9196
</div>
@@ -100,38 +105,38 @@
100105
101106
export default {
102107
mixins: [
103-
mapModules({ detail: 'topic-detail', user: 'user-self' }),
108+
mapModules({ data: 'topic-detail', self: 'user-self' }),
104109
mapRules({ route: 'topic-detail' })
105110
],
106111
components: { replyBox },
107112
computed: {
108-
data () {
109-
return this.detail.data
113+
topic () {
114+
return this.data.topic
110115
},
111116
author () {
112-
return this.detail.data.author
117+
return this.data.topic.author
113118
},
114119
replies () {
115-
return this.detail.data.replies
120+
return this.data.topic.replies
116121
}
117122
},
118123
methods: {
119124
testThing (ups) { // 验证是否点赞
120-
return ups.indexOf(this.user.data.id || '') > -1
125+
return ups.indexOf(this.self.id || '') > -1
121126
},
122127
fabulousItem ({ ups, id }) { // 点赞
123-
if (!this.user.data.id) return this.$router.push('/login')
124-
var index = ups.indexOf(this.user.data.id)
128+
if (!this.self.id) return this.$router.push('/login')
129+
var index = ups.indexOf(this.self.id)
125130
if (index > -1) {
126131
ups.splice(index, 1)
127132
} else {
128-
ups.push(this.user.data.id)
133+
ups.push(this.self.id)
129134
}
130135
http.post(`/reply/${id}/ups`)
131136
},
132137
commentShow (item) { // 显示隐藏回复框
133-
if (!this.user.data.id) return this.$router.push('/login')
134-
this.detail.commentId = this.detail.commentId === item.id ? null : item.id
138+
if (!this.self.id) return this.$router.push('/login')
139+
this.data.commentId = this.data.commentId === item.id ? null : item.id
135140
}
136141
}
137142
}

src/pages/topic/detail/reply-box.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
export default {
1818
mixins: [
19-
mapModules({ detail: 'topic-detail', user: 'user-self' })
19+
mapModules({ topic: 'topic-detail' })
2020
],
2121
props: {
2222
replyId: { // 评论的评论id,如果没有则是对主题的评论
@@ -53,8 +53,7 @@ source [vue-cnode mobile 2.0](http://lzxb.name/vue-cnode/)`
5353
if (success) {
5454
this.content = ''
5555
this.$emit('success')
56-
this.detail.commentId = null
57-
this.$vuet.fetch('topic-detail')
56+
this.topic.commentId = null
5857
} else {
5958
utils.toast(error_msg)
6059
}

0 commit comments

Comments
 (0)