app_tree_planting/pages/news/index.vue
2023-12-13 10:20:14 +08:00

1088 lines
24 KiB
Vue

<template>
<view class="page">
<view class="status-bar"></view>
<view class="content">
<scroller @init="initScroller" @down="refreshData" @up="getData" :up="optUp"
@scroll="navFloatShow(scroller)" :fixed="false">
<!-- 搜索框 -->
<view :class="fixedSearch? 'fixed-box':'nofixed-box'">
<view class="search">
<view class="search-content">
<image src="../../static/images/ic_search.png" class="icon" mode="aspectFill"></image>
<input @input="onSearchInput" placeholder="请输入关键字搜索" />
</view>
<view class="btn" @click="doSearch">搜索</view>
</view>
</view>
<!-- 轮播图 -->
<swiper class="swiper" :indicator-dots="true" :autoplay="true" indicator-color="#E4E4E4"
indicator-active-color="#009749" :circular="true">
<swiper-item v-for="(item, index) in slider" :key="index" class="swiper-item">
<image :lazy-load="true" :src="item.imageUrl" mode="scaleToFill" @click="openDetail(item)">
</image>
</swiper-item>
</swiper>
<!-- 功能按钮 -->
<!-- <scroll-view scroll-x="true" style="white-space: nowrap;margin-top: 10rpx;height: 140rpx;">
<view class="func-item" @click="openTrees">
<image src="../../static/images/ic_old_tree_icon.png" mode="scaleToFill"></image>
<view class="txt">古树名木</view>
</view>
<view class="func-item" @click="openGift">
<image src="../../static/images/ic_old_tree_icon.png" mode="scaleToFill"></image>
<view class="txt">捐资捐物</view>
</view>
<block v-for="(item,index) in funcList" :key="index">
<view class="func-item" @click="openOther(item)">
<image
:src="item.directoriesPhoto=='' ? '/static/images/ic_old_tree_icon.png':imgUrl+item.directoriesPhoto"
mode="scaleToFill"></image>
<view class="txt">{{item.directoriesName}}</view>
</view>
</block>
</scroll-view> -->
<!-- 新闻列表 -->
<articleList :list="list" :imgUrl="imgUrl" />
</scroller>
</view>
<pageLoading v-if="showPageLoading"></pageLoading>
<view v-if="isUpdate">
<view class="update-view">
<text class="update-title">App更新</text>
<view class="update-tip">新版更新内容</view>
<view class="update-content">
修复已知Bug,更新App功能
</view>
<block v-if="!downloading">
<view class="update-btns">
<view class="btn-cancel" @click="cancelUpdate()">
取消
</view>
<view class="btn-confirm" @click="startDownloadApk()">
<image class="icon" src="/static/ic_download.png"></image>
<view class="sure">马上升级</view>
</view>
</view>
</block>
<view style="width: 100%;" v-else>
<progress style="width: 100%;" activeColor="#09BB07" stroke-width="3" show-info
:percent="downloadProgress" backgroundColor="#999999"></progress>
</view>
</view>
</view>
</view>
</template>
<script>
import scroller from '@/components/scroller/scroller.vue';
import articleList from '@/components/article/list.vue';
import pageLoading from '@/components/loading/pageLoading.vue';
import iconfont from '@/components/iconfont/iconfont.vue';
import util from '@/common/util.js';
import sm2 from 'sm-crypto'
export default {
components: {
articleList,
pageLoading,
scroller,
iconfont,
},
data() {
return {
scroller: {},
optUp: {
auto: true,
onScroll: true,
page: {
num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
size: 10 //每页数据条数,默认10
},
empty: {
tip: '暂无文章~'
}
},
category_id: 1,
category_index: 0,
scroll_category_id: 'scroll_category_id_0',
currentSliderIndex: 0,
category: [],
showMenu: false,
slider: [],
list: [],
showNoData: false,
showPageLoading: true,
showNavFloat: false,
navBarHeight: '',
token: "",
searchContent: "",
baseurl: this.$api.common.baseUrl,
imgUrl: this.$api.common.imgUrl,
upgradeType: 'pkg', //pkg 整包 wgt 升级包
upgradeContent: '', //更新内容
upgradeUrl: '', //更新地址
funcList: [],
fixedSearch: false,
isUpdate: false,
downloading: false,
downloadProgress: 0,
};
},
onShow() {
this.$initPageTitle(); //初始化页面标题
console.log("page=onShow")
/*导航栏高度*/
if (this.navBarHeight == '') {
this.navBarHeight = this.$app.getNaviBarHeight();
}
// /*来源是登录时更新*/
// let source = uni.getStorageSync('source');
// console.log(source)
// if (source == 'login') {
// uni.removeStorageSync('source');
// this.loadData();
// }
this.token = getApp().globalData.token
let userInfo = getApp().globalData.userInfo
if (this.token && this.token != '' && userInfo.name == undefined) {
this.getUserInfo()
}
},
onShareAppMessage() {
return {
path: '/pages/article/index',
success: function(e) {},
title: '全民植树'
};
},
onLoad(e) {
// #ifdef APP-PLUS
this.getAppVersion()
// #endif
this.getBannerList();
},
onPullDownRefresh() {
uni.showLoading({
title: '刷新中'
});
this.loadData();
},
methods: {
sm3SignTokenParam(code) {
var uuid = this.getUUID()
var time = new Date().getTime()
const data = "app_id=" + this.$api.common.msbAppId + "&app_secret=" + this.$api.common.msbAppSecret +
"&code=" + code + "&grant_type=authorization_code" + "&time=" + time + "&uuid=" + uuid
var params = {
uuid: uuid,
sign: sm2.sm3(data),
time: time
}
return params;
},
getParamsArg(url) {
let params = url.split('?')[1];
let paramsObj = {};
if (typeof(params) == 'undefined' || params == null) {
return paramsObj;
}
let paramsKVs = params.split('&');
for (let i = 0; i < paramsKVs.length; i++) {
let item = paramsKVs[i];
let kvs = item.split('=');
if (kvs.length === 1) {
paramsObj[kvs[0]] = null;
continue;
}
paramsObj[kvs[0]] = decodeURI(item.replace(kvs[0] + '=', ''));
}
return paramsObj;
},
sm3SignUserBaseInfo(token) {
var uuid = this.getUUID()
var time = new Date().getTime()
const data = "app_id=" + this.$api.common.msbAppId + "&app_secret=" + this.$api.common.msbAppSecret +
"&auth_token=" + token + "&time=" + time + "&uuid=" + uuid
var params = {
uuid: uuid,
sign: sm2.sm3(data),
time: time
}
return params;
},
getUUID() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
},
getAuthorize() {
var _self = this;
uni.showLoading({
title: '加载中...'
})
this.$app.request({
url: this.$api.common.getMsbAuthorize,
method: 'GET',
data: {
app_id: this.$api.common.msbAppId,
scope: 'base_info%2Cauth_user',
redirect_uri: encodeURI(
'https://app.zwfw.nmg.gov.cn/rhpt/16e8a8a578025000')
},
dataType: 'json',
success: res => {
if (res.data && res.data.code) {
_self.getMsbToken(res.data.code)
}
},
fail: error => {
console.log(error)
uni.hideLoading()
},
complete: res => {}
});
},
getMsbToken(code) {
var _self = this;
var signParams = _self.sm3SignTokenParam(code)
this.$app.request({
url: _self.$api.common.getToken,
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
app_id: _self.$api.common.msbAppId,
grant_type: 'authorization_code',
code: code,
sign: signParams.sign,
time: signParams.time,
uuid: signParams.uuid
},
dataType: 'json',
success: res => {
},
fail: error => {
console.log(error)
uni.hideLoading()
},
complete: res => {
console.log(res)
uni.hideLoading()
if (res.data && res.data.code == 1000) {
_self.getMsbUserInfo(res.data.data.token)
}
}
});
},
getMsbUserInfo(token) {
var _self = this;
var params = _self.sm3SignUserBaseInfo(token)
this.$app.request({
url: this.$api.common.getMsbUserInfo,
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
app_id: _self.$api.common.msbAppId,
auth_token: token,
sign: params.sign,
time: params.time,
uuid: params.uuid
},
dataType: 'json',
success: res => {
},
fail: error => {
console.log(error)
uni.hideLoading()
},
complete: res => {
uni.hideLoading()
if (res.data && res.data.code == 1000) {
_self.doLogin(res.data.data)
}
}
});
},
doLogin(user) {
console.log(user)
uni.showLoading({
title: '加载中...'
})
var _self = this;
this.$app.request({
url: _self.$api.user.msbLogin,
method: 'POST',
data: {
custName: user.custName,
mobilePhone: user.mobilePhone
},
dataType: 'json',
success: res => {
uni.hideLoading()
getApp().globalData.token = res.data
},
fail: error => {
uni.hideLoading()
uni.showToast({
icon: 'error',
title: '请稍后重新进入'
})
},
complete: res => {}
});
},
onSearchInput: function(event) {
this.searchContent = event.target.value
console.log(event.target.value)
if (event.target.value == "") {
this.refreshData()
}
},
openDetail(item) {
if ('古树名木' == item.newsContentTitle) {
uni.navigateTo({
url: '/pages/news/oldtrees'
})
} else {
uni.navigateTo({
url: '/pages/news/newsdetail?id=' + item.newsContentId
})
}
},
cancelUpdate() {
this.isUpdate = false
},
//捐资捐物
openGift() {
uni.navigateTo({
url: '/pages/news/giftpage'
})
},
openLogin() {
uni.navigateTo({
url: '/pages/user/login'
})
},
/*初始化滚动*/
initScroller(scroller) {
this.scroller = scroller;
this.loadData();
},
/*刷新数据*/
refreshData() {
uni.showLoading({
title: '刷新中'
});
this.scroller.resetUpScroll();
this.getBannerList();
this.funcList = [];
// this.getMainFunc();
},
/*加载数据*/
loadData() {
this.slider = [];
this.list = [];
this.currentSliderIndex = 0;
this.scroller.resetUpScroll();
},
/*获取子类别数据*/
getCategory() {
console.log("获取类别")
this.$app.request({
url: this.$api.news.getMainFun,
method: 'GET',
data: {
'newsDirectoriesId': this.$api.news.NEWS_MAIN_TAB
},
dataType: 'json',
success: res => {
if (res != undefined && res.length > 0) {
this.category = res;
if (this.category_index > -1) {
let nextIndex = this.category_index - 1;
nextIndex = nextIndex <= 0 ? 0 : nextIndex;
this.scroll_category_id = `category_id-${nextIndex}`; //动画滚动,滚动至中心位置
}
} else {
this.$alert(res.msg);
}
},
complete: res => {}
});
},
/*获取数据*/
getData() {
this.$app.request({
url: this.$api.news.getNewsList,
data: {
newsDirectoriesId: this.$api.news.NEWS_MAIN_ID,
page: this.scroller.num,
rows: this.scroller.size,
keywords: this.searchContent
},
method: 'GET',
dataType: 'json',
success: res => {
if (res.rows != undefined) {
if (this.scroller.num == 1) {
this.list = [];
}
this.list = this.list.concat(res.rows);
this.scroller.endBySize(res.rows.length, res.rows.total);
this.showPageLoading = false;
} else {
this.scroller.endSuccess();
this.$alert(res.msg);
}
},
fail: res => {
this.scroller.endErr();
},
complete: res => {
console.log(res)
uni.stopPullDownRefresh();
uni.hideLoading();
}
});
},
/*切换导航*/
categoryChange(category_id, index) {
this.showMenu = false;
this.category_index = index;
this.category_id = category_id;
var nextIndex = index - 1;
nextIndex = nextIndex <= 0 ? 0 : nextIndex;
this.scroll_category_id = `category_id-${nextIndex}`; //动画滚动,滚动至中心位置
this.loadData();
// #ifdef H5
// uni.navigateTo({
// url: '/pages/article/list?category_id=' + this.category_id + '&category_index=' + this.category_index
// });
// #endif
},
/*广告切换*/
sliderChange: function(e) {
this.currentSliderIndex = e.detail.current;
},
/*滚动时导航栏浮动*/
navFloatShow(scroller) {
if (scroller) {
if (scroller.scrollTop > 40) {
if (!this.fixedSearch) {
this.fixedSearch = true;
}
} else {
if (this.fixedSearch) {
this.fixedSearch = false;
}
}
}
},
/*菜单框展示*/
menuShow(value) {
this.showMenu = value;
},
/*隐藏导航浮动*/
navFloatHide() {
this.showNavFloat = false;
},
/*获取banner*/
getBannerList() {
this.$app.request({
url: this.$api.news.getNewsList,
method: 'GET',
data: {
'newsDirectoriesId': this.$api.news.NEWS_BANNER_ID,
'rows': '5',
'page': '1'
},
dataType: 'json',
success: res => {
if (res.rows != undefined && res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
res.rows[i].imageUrl = this.$api.news.imgUrl + res.rows[i]
.newsContentCoverList[0]
.contentCoverId
}
this.showPageLoading = false;
this.scroller.endSuccess();
this.slider = res.rows
}
},
complete: res => {
console.log(res)
this.scroller.endBySize(1, 1);
uni.stopPullDownRefresh();
uni.hideLoading();
this.showPageLoading = false;
}
});
},
getUserInfo() {
this.$app.request({
url: this.$api.user.getUserInfo,
method: 'GET',
header: {
token: this.token
},
success: res => {
if (res) {
getApp().globalData.userInfo = res;
uni.setStorageSync("userInfo", res);
}
},
complete: res => {
}
})
},
getAppVersion(version) {
var _self = this;
var versionUrl = _self.$api.common.getAppVersion;
var downloadUrl = _self.$api.common.appDownloadUrl
uni.request({
url: versionUrl,
success(res) {
console.log(res)
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
var appId = wgtinfo.appid;
var appVersion = wgtinfo.versionCode;
if (res.data.data && res.data.data > appVersion) {
_self.isUpdate = true;
} else {}
});
},
fail(error) {
console.log(error)
}
})
},
startDownloadApk() {
var _self = this;
var downloadUrl = _self.$api.common.appDownloadUrl;
console.log(downloadUrl)
_self.downloading = true
var downloadTask = uni.downloadFile({
url: downloadUrl,
success: (downloadResult) => {
console.log(downloadResult)
if (downloadResult.statusCode === 200) {
_self.isUpdate = false
plus.runtime.install(downloadResult.tempFilePath, {
force: false,
}, function() {
plus.runtime.restart();
}, (e) => {
console.log(e);
uni.showToast({
title: '安装升级包失败',
icon: 'none'
})
});
} else {
_self.isUpdate = false
uni.showToast({
title: '下载失败,请稍后重试',
icon: 'none'
})
}
},
fail(error) {
_self.isUpdate = false
uni.showToast({
title: '下载失败,请稍后重试',
icon: 'none'
})
}
});
downloadTask.onProgressUpdate((e) => {
console.log(e)
_self.downloadProgress = e.progress
})
},
doSearch() {
uni.hideKeyboard()
if (this.searchContent == "") {
this.$alert("请输入关键字");
}
this.refreshData()
},
getMainFunc() {
//
var _self = this;
uni.request({
url: _self.$api.news.getMainFunc,
data: {
directoriesParentId: _self.$api.news.NEWS_MAIN_FUNC
},
success(res) {
if (res.statusCode == 200) {
_self.funcList = res.data
}
},
fail(error) {}
})
},
//古树名木
openTrees() {
uni.navigateTo({
url: '/pages/news/oldtrees'
})
},
//打开其他
openOther(item) {
//判断是跳详情还是列表
if ('0' == item.directoriesView) {
uni.navigateTo({
url: '/pages/news/newsweb?url=' + item.directoriesTarget2 + '&title=' + item
.directoriesName
})
} else {
uni.navigateTo({
url: '/pages/news/newsList?nId=' + item.newsDirectoriesId + '&title=' + item
.directoriesName
})
}
}
}
};
</script>
<style scoped lang="scss">
page {
height: 100%;
}
.page {
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.content {
flex: 1;
width: 100%;
height: 100rpx;
}
/*头部*/
.top {
/*页面标题*/
.page-title {
display: flex;
justify-content: center;
align-items: center;
height: 90rpx;
text-align: center;
border-bottom: 1rpx solid #efefef;
z-index: 9999;
line-height: 1;
image {
height: 50rpx;
width: 280rpx;
margin-left: -35rpx;
}
}
/* 顶部navbar */
.navbar {
/*分类*/
.menu {
position: relative;
height: 80rpx;
white-space: nowrap;
padding: 15rpx 0 6rpx;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
/*分类*/
.category {
width: 650rpx;
margin-left: 30rpx;
white-space: nowrap;
position: relative;
scroll-view {
width: auto;
.item {
position: relative;
display: inline-block;
margin: 0 10rpx 0;
height: 80rpx;
text-align: left;
padding-top: 7rpx;
//line-height: 80rpx;
&:first-child {
margin-left: 10rpx;
}
&:after {
content: '';
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
transition: 0.3s;
}
.text {
position: relative;
width: auto;
height: auto;
line-height: auto;
display: inline-block;
text {
font-size: 36rpx;
font-weight: bold;
color: #555;
}
image {
position: absolute;
top: 16rpx;
right: -14rpx;
width: 50rpx;
height: 50rpx;
display: none;
}
}
}
.current {
&:after {
width: 50%;
}
.text {
text {
font-size: 40rpx;
font-weight: bold;
color: #262626;
}
image {
display: block;
}
border-bottom: 6rpx solid #8cc7b5;
}
}
}
}
.list {
width: 70rpx;
display: flex;
align-items: center;
justify-content: center;
//box-shadow: -4rpx 0 0 #e9ebee;
//box-shadow: -2px 0 0 #262626;
/deep/ .icon {
font-size: 36rpx;
margin-top: -6rpx;
}
}
}
}
}
.menu-block {
position: absolute;
top: 0;
left: 0;
background: #fff;
border-bottom: 1rpx solid #f5f5f5;
padding: 20rpx 0 50rpx;
z-index: 100;
width: 100%;
//box-shadow: 0 15rpx 10rpx -15rpx #e9ebee;
.list {
padding-left: 10rpx;
text {
background: #f5f7fa;
border-radius: 8rpx;
font-size: 32rpx;
margin: 12rpx 20rpx;
display: inline-block;
height: 72rpx;
width: 144rpx;
line-height: 72rpx;
text-align: center;
}
.current {
color: #fff;
background: #8cc7b5;
//font-size: 32rpx;
}
}
}
/*幻灯片广告 */
.swiper {
height: 368rpx;
margin: 24rpx 29rpx 0rpx 35rpx;
.swiper-item {
position: relative;
height: 368rpx;
width: 100%;
image {
height: 338rpx;
width: 100%;
border-radius: 15rpx;
}
}
/deep/ .uni-swiper-dot {
width: 10rpx !important;
height: 10rpx !important;
background: #c0c0c0 !important;
}
/deep/ .uni-swiper-dot-active {
width: 19rpx !important;
height: 10rpx !important;
background: #009749 !important;
border-radius: 4rpx;
}
/deep/ .uni-swiper-dots-horizontal {
bottom: -10rpx !important;
}
}
/*浮动navbar*/
.floatbar {
//border-bottom: 1rpx solid #e8e8e8;
box-shadow: 0px 2px 2px -2px #e8e8e8;
padding-bottom: 12rpx;
}
/deep/ .no-data {
margin-top: 200rpx;
}
/*搜索*/
.search {
display: flex;
justify-content: space-between;
align-items: center;
padding: 35rpx 28rpx 10rpx 35rpx;
.search-content {
background: #f2f2f2;
height: 67rpx;
flex: 1;
display: flex;
align-items: center;
border-radius: 29rpx;
}
input {
font-size: 27rpx;
font-family: Microsoft YaHei;
font-weight: 400;
color: #B3B3B3;
margin-left: 16rpx;
}
.icon {
width: 30rpx;
height: 30rpx;
margin-left: 26rpx;
}
.btn {
color: #b3b3b3;
margin-left: 25rpx;
}
}
.func-box {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
height: 80rpx;
width: 100%;
white-space: nowrap;
}
.func-item {
display: inline-block;
text-align: center;
width: 160rpx;
height: 186rpx;
margin-right: 21rpx;
&:last-child {
margin-right: 0rpx;
}
image {
width: 60rpx;
height: 60rpx;
}
.txt {
font-size: 28rpx;
color: #262626;
}
}
.fixed-box {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding-top: 40rpx;
background: #ffffff;
z-index: 10;
padding-bottom: 10rpx;
}
.nofixed-box {
position: static;
}
.update-view {
width: 500rpx;
border-radius: 15rpx;
display: flex;
flex-flow: column;
justify-content: flex-start;
align-items: center;
z-index: 9999;
position: fixed;
background: #FFFFFF;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.2), 0 6rpx 20rpx 0 rgba(0, 0, 0, 0.19);
padding: 20rpx;
}
.update-title {
margin-top: 20rpx;
color: #000000;
font-weight: bold;
font-size: 38rpx;
text-align: center;
}
.update-tip {
margin-top: 20rpx;
margin-left: 30rpx;
align-self: flex-start;
font-size: 32rpx;
font-weight: 600;
color: black;
}
.update-content {
font-size: 30rpx;
color: #000000;
}
.update-btns {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
margin-top: 30rpx;
}
.btn-cancel {
padding: 10rpx 0;
text-align: center;
font-size: 30rpx;
font-weight: 500;
}
.btn-confirm {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
font-size: 30rpx;
color: #009749;
.icon {
width: 30rpx;
height: 30rpx;
}
.sure {
padding: 10rpx 0;
text-align: center;
font-size: 30rpx;
font-weight: 500;
}
}
.progress {
margin-bottom: 20rpx;
width: 80%;
}
</style>