Browse Source

refactor: 移除API接口的auth字段并调整页面格式

移除`sharing.js`中API接口的`auth`字段,简化接口配置。同时调整`article.vue`页面的代码格式,提升代码可读性。
master
前端-胡立永 4 weeks ago
parent
commit
242c6480ee
3 changed files with 221 additions and 211 deletions
  1. +0
    -4
      api/model/sharing.js
  2. +1
    -1
      manifest.json
  3. +220
    -206
      pages_order/sharing/article.vue

+ 0
- 4
api/model/sharing.js View File

@ -104,7 +104,6 @@ const api = {
checkShare: { checkShare: {
url: '/fen/checkShare', url: '/fen/checkShare',
method: 'POST', method: 'POST',
auth: true,
showLoading : true, showLoading : true,
}, },
/** /**
@ -113,7 +112,6 @@ const api = {
checkVideoShare: { checkVideoShare: {
url: '/fen/checkVideoShare', url: '/fen/checkVideoShare',
method: 'POST', method: 'POST',
auth: true,
showLoading : true, showLoading : true,
}, },
/** /**
@ -122,7 +120,6 @@ const api = {
checkGroupShare: { checkGroupShare: {
url: '/fen/checkGroupShare', url: '/fen/checkGroupShare',
method: 'POST', method: 'POST',
auth: true,
showLoading : true, showLoading : true,
}, },
/** /**
@ -131,7 +128,6 @@ const api = {
checkArticleShare: { checkArticleShare: {
url: '/fen/checkArticleShare', url: '/fen/checkArticleShare',
method: 'POST', method: 'POST',
auth: true,
showLoading : true, showLoading : true,
}, },
} }


+ 1
- 1
manifest.json View File

@ -1,6 +1,6 @@
{ {
"name" : "unapp模板", "name" : "unapp模板",
"appid" : "__UNI__A010721",
"appid" : "__UNI__197A38F",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",


+ 220
- 206
pages_order/sharing/article.vue View File

@ -1,237 +1,251 @@
<template> <template>
<view>
<view class="content">
<view class="title">{{ detail.headTitle || '' }}</view>
<view class="desc">{{ detail.createTime ? `发布于${detail.createTime}` : '' }}</view>
<editor id="editor" class="editor"
:read-only="true"
@ready="onEditorReady"
></editor>
</view>
<uv-overlay :show="true" :opacity="0" zIndex="998">
<navbar leftClick @leftClick="$utils.navigateBack" />
<button class="btn" type="success" @click="onJoin">查看更多</button>
<popupUnlock ref="popupUnlock" src="../static/sharing/unlock-article.png"></popupUnlock>
<popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
</uv-overlay>
</view>
<view>
<view class="content">
<view class="title">{{ detail.headTitle || '' }}</view>
<view class="desc">{{ detail.createTime ? `发布于${detail.createTime}` : '' }}</view>
<editor id="editor" class="editor" :read-only="true" @ready="onEditorReady"></editor>
</view>
<uv-overlay :show="true" :opacity="0" zIndex="998">
<navbar leftClick @leftClick="$utils.navigateBack" />
<button class="btn" type="success" @click="onJoin">查看更多</button>
<popupUnlock ref="popupUnlock" src="../static/sharing/unlock-article.png"></popupUnlock>
<popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
</uv-overlay>
</view>
</template> </template>
<script> <script>
import { mapState } from 'vuex'
import shareLog from '@/utils/shareLog'
import {
mapState
} from 'vuex'
import shareLog from '@/utils/shareLog'
import popupUnlock from '../components/popupUnlock.vue'
import popupQrCode from '../components/popupQrCode.vue'
import popupUnlock from '../components/popupUnlock.vue'
import popupQrCode from '../components/popupQrCode.vue'
export default { export default {
components: {
popupUnlock,
popupQrCode,
},
components: {
popupUnlock,
popupQrCode,
},
data() { data() {
return { return {
id: null,
detail: {
id: null,
userId: null,
headImage: null,
headTitle: null,
num: 0,
wxCodeImage: null,
textDetails: null,
},
isLocked: true,
}
},
id: null,
detail: {
id: null,
userId: null,
headImage: null,
headTitle: null,
num: 0,
wxCodeImage: null,
textDetails: null,
},
isLocked: true,
}
},
computed: { computed: {
...mapState(['userInfo']), ...mapState(['userInfo']),
}, },
onShow() {
// if (this.id && uni.getStorageSync('token')) {
// this.detail.id ? this.refreshLockStatus() : this.initData()
// }
if (this.detail.id) { //
this.refreshLockStatus()
}
},
async onLoad(option) {
const { id, state, shareId } = option
onShow() {
// if (this.id && uni.getStorageSync('token')) {
// this.detail.id ? this.refreshLockStatus() : this.initData()
// }
if (this.detail.id) { //
this.refreshLockStatus()
}
},
async onLoad(option) {
const {
id,
state,
shareId
} = option
if (shareId) { if (shareId) {
uni.setStorageSync('shareId', shareId) uni.setStorageSync('shareId', shareId)
} }
if (state) { if (state) {
uni.setStorageSync('state', state) uni.setStorageSync('state', state)
} }
if (id) { if (id) {
uni.setStorageSync('id', id) uni.setStorageSync('id', id)
} }
this.id = id
// if (uni.getStorageSync('token')) {
// this.initData()
// } else {
// uni.navigateTo({
// url: '/pages_order/auth/wxLogin'
// })
// }
this.initData()
},
onShareAppMessage(res) {
const {
headTitle,
headImage,
} = this.detail
let o = {
title : headTitle,
imageUrl: headImage,
query: `id=${this.id}&state=3&shareId=${this.userInfo.id}`,
}
//
const params = {
id:this.id,
state:"3",
}
this.$fetch('addLogShareInfo', params)
shareLog.insert(this.id)
return o
},
methods: {
onEditorReady() {
this.id = id
// if (uni.getStorageSync('token')) {
// this.initData()
// } else {
// uni.navigateTo({
// url: '/pages_order/auth/wxLogin'
// })
// }
this.initData()
},
onShareAppMessage(res) {
const {
headTitle,
headImage,
} = this.detail
let o = {
title: headTitle,
imageUrl: headImage,
query: `id=${this.id}&state=3&shareId=${this.userInfo.id}`,
}
//
const params = {
id: this.id,
state: "3",
}
this.$fetch('addLogShareInfo', params)
shareLog.insert(this.id)
return o
},
methods: {
onEditorReady() {
uni.createSelectorQuery().select('#editor').context((res) => { uni.createSelectorQuery().select('#editor').context((res) => {
this.editorCtx = res.context this.editorCtx = res.context
}).exec() }).exec()
}, },
initEditor(html) {
if (!this.editorCtx) {
setTimeout(() => {
this.initEditor(html)
}, 200)
return
}
this.editorCtx.setContents({ html })
},
async fetchDetails(id) {
try {
this.detail = await this.$fetch('getArticleShareInfo', { id })
} catch (err) {
}
},
async initData() {
await this.fetchDetails(this.id)
this.initEditor(this.detail.textDetails)
},
async fetchCheckShare() {
try {
return shareLog.check(this.id, this.detail.num)
} catch (err) {
return {}
}
},
async refreshLockStatus() {
const result = await this.fetchCheckShare()
const { title, open } = result
console.log('--open', open)
this.$refs.popupUnlock.close();
if (open) {
this.isLocked = false
this.$refs.popupQrCode.open()
return
}
title && uni.showToast({
title,
icon: 'none',
duration: 3000
})
},
async onJoin() {
if (!this.isLocked) {
this.$refs.popupQrCode.open()
return
}
const result = await this.fetchCheckShare()
const { open, need_num, num } = result
console.log('--open', open)
if (open) { //
this.isLocked = false
this.$refs.popupQrCode.open()
} else {
uni.showToast({
title: `还需转发${need_num - num}`,
icon: 'none',
})
this.$refs.popupUnlock.open();
}
},
}
}
initEditor(html) {
if (!this.editorCtx) {
setTimeout(() => {
this.initEditor(html)
}, 200)
return
}
this.editorCtx.setContents({
html
})
},
async fetchDetails(id) {
try {
this.detail = await this.$fetch('getArticleShareInfo', {
id
})
} catch (err) {
}
},
async initData() {
await this.fetchDetails(this.id)
this.initEditor(this.detail.textDetails)
},
async fetchCheckShare() {
try {
return shareLog.check(this.id, this.detail.num)
} catch (err) {
return {}
}
},
async refreshLockStatus() {
const result = await this.fetchCheckShare()
const {
title,
open
} = result
console.log('--open', open)
this.$refs.popupUnlock.close();
if (open) {
this.isLocked = false
this.$refs.popupQrCode.open()
return
}
title && uni.showToast({
title,
icon: 'none',
duration: 3000
})
},
async onJoin() {
if (!this.isLocked) {
this.$refs.popupQrCode.open()
return
}
const result = await this.fetchCheckShare()
const {
open,
need_num,
num
} = result
console.log('--open', open)
if (open) { //
this.isLocked = false
this.$refs.popupQrCode.open()
} else {
uni.showToast({
title: `还需转发${need_num - num}`,
icon: 'none',
})
this.$refs.popupUnlock.open();
}
},
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.content {
padding: 40rpx 20rpx;
padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
}
.title {
color: #474747;
font-size: 36rpx;
font-weight: 700;
}
.desc {
color: #A2A2A2;
font-size: 24rpx;
margin-top: 6rpx;
}
.editor {
margin-top: 22rpx;
height: 40vh;
}
.btn {
position: absolute;
width: calc(100% - 60rpx*2);
height: auto;
left: 60rpx;
bottom: 292rpx;
background-color: #07C160;
border: none;
color: #FFFFFF;
font-size: 28rpx;
line-height: 1;
border-radius: 45rpx;
padding: 25rpx 0;
box-sizing: border-box;
}
.content {
padding: 40rpx 20rpx;
padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
}
.title {
color: #474747;
font-size: 36rpx;
font-weight: 700;
}
.desc {
color: #A2A2A2;
font-size: 24rpx;
margin-top: 6rpx;
}
.editor {
margin-top: 22rpx;
height: 40vh;
}
.btn {
position: absolute;
width: calc(100% - 60rpx*2);
height: auto;
left: 60rpx;
bottom: 292rpx;
background-color: #07C160;
border: none;
color: #FFFFFF;
font-size: 28rpx;
line-height: 1;
border-radius: 45rpx;
padding: 25rpx 0;
box-sizing: border-box;
}
</style> </style>

Loading…
Cancel
Save