提交 92ce7994 编写于 作者: 芊里

积分/阅读文章

上级 c8030b4f
...@@ -196,6 +196,13 @@ ...@@ -196,6 +196,13 @@
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path":"uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
"style":{
"navigationBarTitleText": "阅读记录",
"enablePullDownRefresh": false
}
} }
], ],
"globalStyle": { "globalStyle": {
......
...@@ -48,7 +48,11 @@ ...@@ -48,7 +48,11 @@
<script> <script>
import baseappConfig from '@/baseapp.config.js'; import baseappConfig from '@/baseapp.config.js';
import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js'; import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js';
import uParse from '@/components/u-parse/parse.vue'; import uParse from '@/components/u-parse/parse.vue';
const db = uniCloud.database();
const dbCollectionName = 'opendb-news-favorite';
import { mapGetters } from 'vuex';
export default { export default {
components: { components: {
uParse uParse
...@@ -72,9 +76,12 @@ ...@@ -72,9 +76,12 @@
//查询条件 ,更多详见 :https://uniapp.dcloud.net.cn/uniCloud/unicloud-db?id=jsquery //查询条件 ,更多详见 :https://uniapp.dcloud.net.cn/uniCloud/unicloud-db?id=jsquery
where() { where() {
return `_id =="${this.id}"` return `_id =="${this.id}"`
} },
...mapGetters({
'userInfo':'user/info'
})
}, },
onLoad(event) { onLoad(event) {
//获取真实新闻id,通常 id 来自上一个页面 //获取真实新闻id,通常 id 来自上一个页面
if (event.id) { if (event.id) {
this.id = event.id this.id = event.id
...@@ -103,14 +110,28 @@ ...@@ -103,14 +110,28 @@
}) })
} }
}, },
methods: { methods: {
setFavorite(){
if(!this.userInfo)return
db.collection(dbCollectionName).add({
article_id:this.id,
article_title:this.title,
user_id:this.userInfo._id
}).then((res) => {
console.log(res);
}).catch(err=>{
console.log(err);
})
},
loadData(data) { loadData(data) {
//如果上一页未传递标题过来(如搜索直达详情),则从新闻详情中读取标题 //如果上一页未传递标题过来(如搜索直达详情),则从新闻详情中读取标题
if (this.title == '' && data[0].title) { if (this.title == '' && data[0].title) {
this.title = data[0].title this.title = data[0].title
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: data[0].title title: data[0].title
}) });
this.setFavorite();
} }
}, },
/** /**
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
mapGetters, mapGetters,
mapMutations mapMutations
} from 'vuex'; } from 'vuex';
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'; import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
const db = uniCloud.database(); const db = uniCloud.database();
const dbCollectionName = 'uni-id-scores'; const dbCollectionName = 'uni-id-scores';
export default { export default {
data() { data() {
...@@ -61,21 +61,22 @@ ...@@ -61,21 +61,22 @@
} }
], ],
ucenterList: [ ucenterList: [
[ [
// #ifdef APP-PLUS // #ifdef APP-PLUS
{ {
title: '去评分', title: '去评分',
event: 'gotoMarket' event: 'gotoMarket'
}, },
// #endif // #endif
{ {
title: '阅读过的文章', title: '阅读过的文章',
to: '' to: '/uni_modules/uni-news-favorite/pages/uni-news-favorite/list',
}, { }, {
title: '我的积分', title: '我的积分',
to: '', to: '',
event:'getScore' event: 'getScore'
}], }
],
[{ [{
title: '问题与反馈', title: '问题与反馈',
to: '/uni_modules/uni-feedback/pages/opendb-feedback/list' // /pages/ucenter/uni-feedback/uni-feedback uni_modules/uni-feedback/pages/opendb-feedback/list to: '/uni_modules/uni-feedback/pages/opendb-feedback/list' // /pages/ucenter/uni-feedback/uni-feedback uni_modules/uni-feedback/pages/opendb-feedback/list
...@@ -86,27 +87,26 @@ ...@@ -86,27 +87,26 @@
] ]
} }
}, },
onLoad() { onLoad() {
//#ifdef APP-PLUS //#ifdef APP-PLUS
this.ucenterList[this.ucenterList.length - 1].unshift( this.ucenterList[this.ucenterList.length - 1].unshift({
{ title: '检查更新',
title: '检查更新', rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
rightText: this.appVersion.version+'-'+this.appVersion.versionCode, event: 'checkVersion',
event: 'checkVersion', showBadge: this.appVersion.hasNew
showBadge: this.appVersion.hasNew })
}
)
//#endif //#endif
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
userInfo: 'user/info', userInfo: 'user/info',
login: 'user/hasLogin' login: 'user/hasLogin'
}) })
// #ifdef APP-PLUS // #ifdef APP-PLUS
,appVersion() { ,
return getApp().appVersion appVersion() {
} return getApp().appVersion
}
// #endif // #endif
}, },
methods: { methods: {
...@@ -126,8 +126,8 @@ ...@@ -126,8 +126,8 @@
this[item.event](); this[item.event]();
} }
}, },
async checkVersion() { async checkVersion() {
console.log(await callCheckVersion()); console.log(await callCheckVersion());
checkUpdate() checkUpdate()
}, },
goLogin() { goLogin() {
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
/** /**
* 去应用市场评分 * 去应用市场评分
*/ */
gotoMarket() { gotoMarket() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform == "ios") { if (uni.getSystemInfoSync().platform == "ios") {
// 这里填写appstore应用id // 这里填写appstore应用id
...@@ -168,25 +168,33 @@ ...@@ -168,25 +168,33 @@
main.startActivity(intent); main.startActivity(intent);
} }
// #endif // #endif
}, },
/** /**
* 获取积分信息 * 获取积分信息
*/ */
getScore() { getScore() {
uni.showLoading({
mask: true if (!this.userInfo) return uni.showToast({
}) title: '请登录后查看积分',
db.collection(dbCollectionName).field('score,balance').get().then((res) => { icon: 'none'
const data = res.result.data[0] });
console.log(data); uni.showLoading({
}).catch((err) => { mask: true
uni.showModal({ })
content: err.message || '请求服务失败', db.collection(dbCollectionName).field('score,balance').get().then((res) => {
showCancel: false const data = res.result.data[0];
}) uni.showToast({
}).finally(() => { title: '当前积分为' + data.balance,
uni.hideLoading() icon: 'none'
}) });
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
} }
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"bsonType": "object", "bsonType": "object",
"required": ["user_id", "article_id"], "required": ["user_id", "article_id"],
"permission": { "permission": {
"read": true, "read": "doc.uid == auth.uid",
"create": "auth.uid != null", "create": "auth.uid != null",
"update": false, "update": false,
"delete": "doc.uid == auth.uid" "delete": "doc.uid == auth.uid"
...@@ -10,11 +10,15 @@ ...@@ -10,11 +10,15 @@
"properties": { "properties": {
"_id": { "_id": {
"description": "ID,系统自动生成" "description": "ID,系统自动生成"
}, },
"article_id": { "article_id": {
"bsonType": "string", "bsonType": "string",
"description": "文章id,参考opendb-news-articles表", "description": "文章id,参考opendb-news-articles表",
"foreignKey": "opendb-news-articles._id" "foreignKey": "opendb-news-articles._id"
},
"article_title":{
"bsonType": "string",
"description": "文章标题"
}, },
"user_id": { "user_id": {
"bsonType": "string", "bsonType": "string",
......
{ {
"bsonType": "object", "bsonType": "object",
"required": ["user_id", "score", "balance"], "required": ["user_id", "score", "balance"],
"permission": {
"read": true,
"create": true,
"update": "doc._id == auth.uid",
"delete": false
},
"properties": { "properties": {
"_id": { "_id": {
"description": "ID,系统自动生成" "description": "ID,系统自动生成"
......
// 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
const validator = {
"article_id": {
"rules": [
{
"required": true
},
{
"format": "string"
}
]
},
"create_date": {
"rules": [
{
"format": "timestamp"
}
]
}
}
const enumConverter = {}
export { validator, enumConverter }
{
"id": "opendb-news-favorite",
"displayName": "opendb-news-favorite",
"version": "1.0.0",
"description": "",
"keywords": [
"opendb-news-favorite"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"uniCloud",
"Admin插件"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [
"uni-dateformat",
"uni-badge",
"uni-icons",
"uni-link",
"uni-load-more",
"uni-forms",
"uni-group",
"uni-list",
"uni-fab",
"uni-datetime-picker",
"uni-file-picker",
"uni-easyinput"
],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "u",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "y",
"QQ": "y"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
<template>
<view class="uni-container">
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
<uni-forms-item name="article_id" label="" required>
<uni-easyinput placeholder="文章id,参考opendb-news-articles表" v-model="formData.article_id" />
</uni-forms-item>
<uni-forms-item name="create_date" label="">
<uni-datetime-picker return-type="timestamp" :value="formData.create_date" />
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" @click="submit">提交</button>
</view>
</uni-forms>
</view>
</template>
<script>
import { validator } from '../../js_sdk/validator/opendb-news-favorite.js';
const db = uniCloud.database();
const dbCollectionName = 'opendb-news-favorite';
function getValidator(fields) {
let reuslt = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
reuslt[key] = validator[key]
}
}
return reuslt
}
export default {
data() {
return {
formData: {
"article_id": "",
"create_date": null
},
formOptions: {},
rules: {
...getValidator(["article_id","create_date"])
}
}
},
onReady() {
this.$refs.form.setRules(this.rules)
},
methods: {
/**
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.submit().then((res) => {
this.submitForm(res)
}).catch((errors) => {
uni.hideLoading()
})
},
submitForm(value) {
// 使用 clientDB 提交数据
db.collection(dbCollectionName).add(value).then((res) => {
uni.showToast({
icon: 'none',
title: '新增成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
}
</script>
<style>
.uni-container {
padding: 15px;
}
.uni-input-border,
.uni-textarea-border {
width: 100%;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
box-sizing: border-box;
}
.uni-input-border {
padding: 0 10px;
height: 35px;
}
.uni-textarea-border {
padding: 10px;
height: 80px;
}
.uni-button-group {
margin-top: 50px;
display: flex;
justify-content: center;
}
.uni-button {
width: 184px;
padding: 12px 20px;
font-size: 14px;
border-radius: 4px;
line-height: 1;
margin: 0;
}
</style>
<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" collection="opendb-news-favorite" field="article_id,create_date" :where="queryWhere" :getone="true" :manual="true">
<view v-if="error">{{error.message}}</view>
<view v-else-if="loading">
<uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
</view>
<view v-else-if="data">
<view>
<text>article_id:</text>
<text>{{data.article_id}}</text>
</view>
<view>
<text>create_date:</text>
<uni-dateformat :date="data.create_date" :threshold="[0, 0]" />
</view>
</view>
</unicloud-db>
<view class="btns">
<button type="primary" @click="handleUpdate">修改</button>
<button type="warn" class="btn-delete" @click="handleDelete">删除</button>
</view>
</view>
</template>
<script>
// 由schema2code生成,包含校验规则和enum静态数据
import { enumConverter } from '../../js_sdk/validator/opendb-news-favorite.js';
export default {
data() {
return {
queryWhere: '',
loadMore: {
contentdown: '',
contentrefresh: '',
contentnomore: ''
},
options: {
// 将scheme enum 属性静态数据中的value转成text
...enumConverter
}
}
},
onLoad(e) {
this._id = e.id
},
onReady() {
if (this._id) {
this.queryWhere = '_id=="' + this._id + '"'
}
},
methods: {
handleUpdate() {
// 打开修改页面
uni.navigateTo({
url: './edit?id=' + this._id,
events: {
// 监听修改页面成功修改数据后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
})
},
handleDelete() {
this.$refs.udb.remove(this._id, {
success: (res) => {
// 删除数据成功后跳转到list页面
uni.navigateTo({
url: './list'
})
}
})
}
}
}
</script>
<style>
.container {
padding: 10px;
}
.btns {
margin-top: 10px;
display: flex;
flex-direction: row;
}
.btns button {
flex: 1;
}
.btn-delete {
margin-left: 10px;
}
</style>
<template>
<view class="uni-container">
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
<uni-forms-item name="article_id" label="" required>
<uni-easyinput placeholder="文章id,参考opendb-news-articles表" v-model="formData.article_id" />
</uni-forms-item>
<uni-forms-item name="create_date" label="">
<uni-datetime-picker return-type="timestamp" :value="formData.create_date" />
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" @click="submit">提交</button>
</view>
</uni-forms>
</view>
</template>
<script>
import { validator } from '../../js_sdk/validator/opendb-news-favorite.js';
const db = uniCloud.database();
const dbCollectionName = 'opendb-news-favorite';
function getValidator(fields) {
let reuslt = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
reuslt[key] = validator[key]
}
}
return reuslt
}
export default {
data() {
return {
formData: {
"article_id": "",
"create_date": null
},
formOptions: {},
rules: {
...getValidator(["article_id","create_date"])
}
}
},
onLoad(e) {
const id = e.id
this.formDataId = id
this.getDetail(id)
},
onReady() {
this.$refs.form.setRules(this.rules)
},
methods: {
/**
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.submit().then((res) => {
this.submitForm(res)
}).catch((errors) => {
uni.hideLoading()
})
},
submitForm(value) {
// 使用 clientDB 提交数据
db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => {
uni.showToast({
icon: 'none',
title: '修改成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
},
/**
* 获取表单数据
* @param {Object} id
*/
getDetail(id) {
uni.showLoading({
mask: true
})
db.collection(dbCollectionName).doc(id).field('article_id').get().then((res) => {
const data = res.result.data[0]
if (data) {
this.formData = data
}
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
}
</script>
<style>
.uni-container {
padding: 15px;
}
.uni-input-border,
.uni-textarea-border {
width: 100%;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
box-sizing: border-box;
}
.uni-input-border {
padding: 0 10px;
height: 35px;
}
.uni-textarea-border {
padding: 10px;
height: 80px;
}
.uni-button-group {
margin-top: 50px;
display: flex;
justify-content: center;
}
.uni-button {
width: 184px;
padding: 12px 20px;
font-size: 14px;
border-radius: 4px;
line-height: 1;
margin: 0;
}
</style>
<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="opendb-news-favorite" field="article_id">
<view v-if="error">{{error.message}}</view>
<view v-else-if="data">
<uni-list>
<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item)">
<view slot="body">
<text>{{item.article_title || item.article_id}}</text>
<uni-dateformat :date="item.create_date" format="yyyy-MM-dd hh:mm"
:threshold="[0, 0]" />
</view>
</uni-list-item>
</uni-list>
</view>
<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
</unicloud-db>
</view>
</template>
<script>
export default {
data() {
return {
loadMore: {
contentdown: '',
contentrefresh: '',
contentnomore: ''
}
}
},
onPullDownRefresh() {
this.$refs.udb.loadData({
clear: true
}, () => {
uni.stopPullDownRefresh()
})
},
onReachBottom() {
this.$refs.udb.loadMore()
},
methods: {
handleItemClick(item) {
console.log(item);
uni.navigateTo({
url: '/pages/list/detail?id='+item.article_id+'&title='+(item.article_title || '')
})
},
fabClick() {
// 打开新增页面
uni.navigateTo({
url: './add',
events: {
// 监听新增数据成功后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
})
}
}
}
</script>
<style>
</style>
# opendb-news-favorite
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册