添加设置功能

This commit is contained in:
yi-ge 2020-09-19 14:32:07 +08:00
parent 4c6ad37f3a
commit 26cdfd79b2
3 changed files with 112 additions and 9 deletions

View File

@ -562,3 +562,6 @@ blockquote
.articelContent .articelContent
a a
color #de8787 color #de8787
.toasted-container
z-index 9999999 !important

View File

@ -160,22 +160,27 @@
| 下一篇 {{ articels.next ? "(" + decodeTitle(articels.next.post_name) + ")" : "" }}   | 下一篇 {{ articels.next ? "(" + decodeTitle(articels.next.post_name) + ")" : "" }}  
Icon(:icon='["fas", "chevron-right"]') Icon(:icon='["fas", "chevron-right"]')
modal.modal-setting(name='setting') modal.modal-setting(name='setting')
.vue-modal-content .vue-modal-content(v-loading='form.loading')
p.vue-modal-title
| 评论回复提醒
Form(ref='form', :model='form', label-width='130px') Form(ref='form', :model='form', label-width='130px')
FormItem(label='手机号') FormItem(label='手机号')
Input(v-model='form.phone') Input(v-model='form.phone', size='small')
FormItem(label='发送提醒到手机') FormItem(label='发送提醒到手机')
Switch(v-model='form.sendPhone') VueSwitch(v-model='form.sendPhone')
FormItem(label='邮箱') FormItem(label='邮箱')
Input(v-model='form.phone') Input(v-model='form.email', size='small')
FormItem(label='发送提醒到邮箱') FormItem(label='发送提醒到邮箱')
Switch(v-model='form.sendEmail') VueSwitch(v-model='form.sendEmail')
.vue-modal-buttons .vue-modal-buttons
button.vue-modal-button(type='button', @click.stop='hideSettings')
| 关闭
button.vue-modal-button( button.vue-modal-button(
type='button', type='button',
@click.stop='$modal.hide("setting")' @click.stop='saveSettings',
style='background-color: #409eff;color: #fff;'
) )
| 关闭 | 保存
</template> </template>
<script> <script>
@ -185,7 +190,7 @@ import { Form, FormItem, Input, Switch } from 'element-ui'
export default { export default {
components: { components: {
Form, FormItem, Input, Switch Form, FormItem, Input, VueSwitch: Switch
}, },
async asyncData ({ route, app, $axios, redirect }) { async asyncData ({ route, app, $axios, redirect }) {
let draftStr = '' let draftStr = ''
@ -276,6 +281,7 @@ export default {
} }
], ],
form: { form: {
loading: true,
phone: '', phone: '',
sendPhone: true, sendPhone: true,
email: '', email: '',
@ -291,6 +297,7 @@ export default {
try { try {
this.visitorInfo = JSON.parse(window.localStorage.visitorInfo) this.visitorInfo = JSON.parse(window.localStorage.visitorInfo)
this.getCommentWithVisitorInfo(this.postID) this.getCommentWithVisitorInfo(this.postID)
this.checkSettings()
} catch (_) { } } catch (_) { }
} }
@ -305,6 +312,8 @@ export default {
this.editorReplyObj.vditor.options.upload.headers = { this.editorReplyObj.vditor.options.upload.headers = {
Authorization: 'Bearer ' + this.visitorToken Authorization: 'Bearer ' + this.visitorToken
} }
this.checkSettings()
} }
this.$nextTick(() => { this.$nextTick(() => {
@ -827,7 +836,87 @@ export default {
} }
}, },
commentSetting () { commentSetting () {
this.form.loading = true
this.$modal.show('setting') this.$modal.show('setting')
this.getSettings()
},
hideSettings () {
this.$modal.hide('setting')
this.form.loading = true
if (!localStorage.checkSetting) {
localStorage.checkSetting = new Date().getTime().toString()
}
},
async checkSettings () {
if (!localStorage.checkSetting) {
//
const tmp = await this.$axios({
method: 'get',
url: process.env.baseURL + '/user/settings',
headers: {
Authorization: 'Bearer ' + this.visitorToken
}
})
if (tmp.status === 200 && tmp.data.status === 1 && tmp.data.result && tmp.data.result.sendPhone && tmp.data.result.sendEmail && (!tmp.data.result.phone || !tmp.data.result.email)) {
this.commentSetting()
this.$toasted.show('温馨提示:设置手机号或邮箱,可及时收到回复提醒', {
position: 'top-center',
duration: 5000
})
}
}
},
async getSettings () {
//
const tmp = await this.$axios({
method: 'get',
url: process.env.baseURL + '/user/settings',
headers: {
Authorization: 'Bearer ' + this.visitorToken
}
})
if (tmp.status === 200 && tmp.data.status === 1 && tmp.data.result) {
this.form.phone = tmp.data.result.phone
this.form.sendPhone = tmp.data.result.sendPhone
this.form.email = tmp.data.result.email
this.form.sendEmail = tmp.data.result.sendEmail
this.form.loading = false
} else {
this.$toasted.show('获取设置内容失败,请重试', {
position: 'top-center',
duration: 5000
})
}
},
async saveSettings () {
//
const tmp = await this.$axios({
method: 'post',
url: process.env.baseURL + '/user/settings',
headers: {
Authorization: 'Bearer ' + this.visitorToken
},
data: this.form
})
if (tmp.status === 200 && tmp.data.status === 1) {
this.hideSettings()
this.$toasted.show('保存成功', {
position: 'top-center',
duration: 5000
})
} else {
this.$toasted.show('保存设置失败,请重试', {
position: 'top-center',
duration: 5000
})
}
if (!localStorage.checkSetting) {
localStorage.checkSetting = new Date().getTime().toString()
}
} }
}, },
head () { head () {
@ -1302,9 +1391,18 @@ $logo-width = 64px
z-index 99999 z-index 99999
.vue-modal-content .vue-modal-content
padding 10px padding 10px 20px 10px 10px
box-sizing border-box box-sizing border-box
.vue-modal-title
text-align center
margin-top 5px
margin-bottom 10px
font-weight 500
.el-form-item
margin-bottom 10px
.vue-modal-buttons .vue-modal-buttons
display flex display flex
flex 0 1 auto flex 0 1 auto

View File

@ -30,6 +30,7 @@ import {
} from '@fortawesome/free-regular-svg-icons' } from '@fortawesome/free-regular-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import hljs from 'highlight.js' import hljs from 'highlight.js'
import { Loading } from 'element-ui'
import Swiper from '../components/Swiper' import Swiper from '../components/Swiper'
import Slide from '../components/Slide' import Slide from '../components/Slide'
@ -61,6 +62,7 @@ library.add(
Vue.component('Icon', FontAwesomeIcon) Vue.component('Icon', FontAwesomeIcon)
Vue.component('Swiper', Vue.extend(Swiper)) Vue.component('Swiper', Vue.extend(Swiper))
Vue.component('Slide', Vue.extend(Slide)) Vue.component('Slide', Vue.extend(Slide))
Vue.use(Loading.directive)
export default function (ctx, inject) { export default function (ctx, inject) {
inject('getHatValue', (count, hotConst = 1000) => { inject('getHatValue', (count, hotConst = 1000) => {