<template>
<view>
<u-row>
<u-search v-model="keyword" @focus="active != 3 && tabChange(3)" @custom="tabChange(3)"></u-search>
<view @click="tabChange(0)">推荐</view>
<view @click="tabChange(1)">更新</view>
</u-row>
<view>
<template v-if="!loading">
<u-row style="flex-wrap: wrap;" v-if="active == 0">
<u-col span="4" v-for="(item , index) in recommendList" :key="item.id">
<view class="bg">
<u-row style="flex-wrap: wrap;">
<u-col span="3">
<u-image :src="`${baseUrl}${item.appIcon}`" height="50rpx" width="50rpx"></u-image>
</u-col>
<u-col span="9">
<u-text :text="item.appName" bold size="30"></u-text>
<u-text :text="item.appDescription" lines="2"></u-text>
</u-col>
</u-row>
<u-row>
<u-col span="3">
<u-button size="mini" :loading="downloadingAppIds.includes(item.id)"
:text="downloadingAppIds.includes(item.id) ? '' : getAppStatus(item , installedAppList)"
:color="getAppStatus(item , installedAppList , true)"
:disabled="getAppStatus(item , installedAppList) == '已安装'"
@click="handleDownload(item , getAppStatus(item , installedAppList))"></u-button>
</u-col>
</u-row>
</view>
</u-col>
</u-row>
<u-text text="本周热门" bold size="30" v-if="active == 0"></u-text>
<u-row style="flex-wrap: wrap;">
<u-col span="4" v-for="(item , index) in appList" :key="item.id">
<u-row>
<u-col span="3">
<u-image :src="`${baseUrl}${item.appIcon}`" height="50rpx" width="50rpx"></u-image>
</u-col>
<u-col span="7">
<u-text :text="item.appName" size="30"></u-text>
</u-col>
<u-col span="2">
<u-button size="mini" :loading="downloadingAppIds.includes(item.id)"
:text="downloadingAppIds.includes(item.id) ? '' : getAppStatus(item , installedAppList)"
:color="getAppStatus(item , installedAppList , true)"
:disabled="getAppStatus(item , installedAppList) == '已安装'"
@click="handleDownload(item , getAppStatus(item , installedAppList))"></u-button>
</u-col>
</u-row>
<u-row>
<u-col span="6">
<u-text :text="'发布版本:' + item.appVersion"></u-text>
</u-col>
<u-col span="6">
<u-text :text="'下载次数' + (item.downloadCount || 0)"></u-text>
</u-col>
</u-row>
</u-col>
</u-row>
</template>
</view>
</view>
</template>
<script>
export default {
data() {
return {
baseUrl: uni.$u.http.config.baseURL,
loading: true,
recommendList: [],
appList: [],
downloadingAppIds: [],
installedAppList: [],
keyword: '',
active: 0
}
},
onShow(){
this.getApplicationMarketList()
},
created() {
this.getApplicationMarketList()
},
methods: {
getAppList(){
return new Promise((resolve , reject) => {
// #ifdef APP-PLUS
plus.android.importClass('java.util.ArrayList')
plus.android.importClass('android.content.pm.PackageInfo')
plus.android.importClass('android.content.pm.PackageManager')
let MainActivity = plus.android.runtimeMainActivity()
let PackageManager = MainActivity.getPackageManager()
let pinfo = plus.android.invoke(PackageManager , 'getInstalledPackages' , 0)
if(pinfo != null){
let apklist = []
for(let i = 0; i < pinfo.size(); i++){
let pkginfo = pinfo.get(i)
let issysapk = ((pkginfo.plusGetAttribute('applicationInfo').plusGetAttribute(
'flags') & plus.android.importClass('android.content.pm.ApplicationInfo')
.FLAG_SYSTEM) != 0) ? true : false
if(issysapk == false){
const apkinfo = {
packageName: pkginfo.plusGetAttribute('packageName'),
versionName: pkginfo.plusGetAttribute('versionName')
}
apklist.push(apkinfo)
}
}
resolve(apklist)
}else{
reject([])
}
// #endif
// #ifndef APP-PLUS
resolve([])
// #endif
})
},
async getApplicationMarketList(){
this.loading = true
this.installedAppList = await this.getAppList()
uni.$u.http.get('/control/app/list' , {params: {appName : this.keyword}}).then(res => {
this.appList = res.rows
}).then(() => {
if(this.active == 0){
this.recommendList = this.appList.filter(item => item.isRecommended).slice(0 , 3)
uni.$u.http.get('/control/topic/list').then(res => {
this.appList = res.rows[0].appList
})
}
if(this.active == 1 && this.installedAppList.length){
this.appList = this.appList.filter(item => {
const app = this.installedAppList.find(app => app.packageName === item.appPackageName)
if(app){
return item.appVersion > app.versionName
}
return false
})
}
})
this.loading = false
},
downAndInstallApp(path){
return new Promise((resolve , reject) => {
// #ifdef APP-PLUS
uni.showToast({
title: '开始下载',
icon: 'none'
})
uni.downloadFile({
url: `${this.baseUrl}${path}`,
success(result){
plus.runtime.install(result.tempFilePath , {force: true,})
resolve(result.statusCode)
}
})
// #endif
// #ifndef APP-PLUS
uni.showToast({
title: '请在APP中打开',
icon: 'none'
})
// #endif
})
},
async handleDownload(item , status){
// #ifdef APP-PLUS
this.downloadingAppIds.push(item.id)
// #endif
const result = await this.downAndInstallApp(item.appUrl)
if(result == 200){
this.downloadingAppIds = this.downloadingAppIds.filter(id => id !== item.id)
uni.$u.http.post('/control/record' , {appId: item.id}).then(() => {
this.getApplicationMarketList()
})
if(status == '更新'){
await uni.$u.http.put(`/control/app?id=${item.id}&appVersion=${parseFloat(item.appVersion) + 0.01}`)
}
}
},
getAppStatus(item , installedAppList , color = false){
const app = installedAppList.find((app) => app.packageName === item.appPackageName)
if(app){
if(color){
return item.appVersion > app.versionName ? 'blue' : 'gray'
}
return item.appVersion > app.versionName ? '更新' : '已安装'
}
if(color){
return 'black'
}
return '下载'
},
tabChange(index){
this.active = index
this.appList = []
this.getApplicationMarketList()
}
}
}
</script>
<style scoped>
.bg{
background: url('@/static/market/card_bg1.png') no-repeat;
}
</style>
<template>
<view>
<u-row>
<u-search v-model="keyword" @focus="active != 3 && tabChange(3)" @custom="tabChange(3)"></u-search>
<view @click="tabChange(0)">推荐</view>
<view @click="tabChange(1)">更新</view>
</u-row>
<template v-if="!loading">
<u-row style="flex-wrap: wrap;" v-if="active == 0">
<u-col span="4" v-for="(item , index) in recommendList" :key="item.id">
<view class="bg">
<u-row style="flex-wrap: wrap;">
<u-col span="3">
<u-image :src="`${baseUrl}${item.appIcon}`" height="50rpx" width="50rpx"></u-image>
</u-col>
<u-col span="9">
<u-text :text="item.appName" bold size="30"></u-text>
<u-text :text="item.appDescription" ></u-text>
</u-col>
</u-row>
<u-row>
<u-col span="3">
<u-button :loading="downloadingAppIds.includes(item.id)"
:text="downloadingAppIds.includes(item.id) ? '' : getAppStatus(item , installedAppList)"
:color="getAppStatus(item , installedAppList , true)"
:disabled="getAppStatus(item , installedAppList) == '已安装'"
@click="handleDownload(item , getAppStatus(item , installedAppList))"></u-button>
</u-col>
</u-row>
</view>
</u-col>
</u-row>
<u-text text="本周热门" bold size="30" v-if="active == 0"></u-text>
<u-row>
<u-col span="4" v-for="(item , index) in appList" :key="item.id">
<u-row style="flex-wrap: wrap;">
<u-col span="3">
<u-image :src="`${baseUrl}${item.appIcon}`" height="50rpx" width="50rpx"></u-image>
</u-col>
<u-col span="6">
<u-text :text="item.appName" bold size="30"></u-text>
</u-col>
<u-col span="2">
<u-button :loading="downloadingAppIds.includes(item.id)"
:text="downloadingAppIds.includes(item.id) ? '' : getAppStatus(item , installedAppList)"
:color="getAppStatus(item , installedAppList , true)"
:disabled="getAppStatus(item , installedAppList) == '已安装'"
@click="handleDownload(item , getAppStatus(item , installedAppList))"></u-button>
</u-col>
</u-row>
<u-row>
<u-text :text="'发布版本:' + item.appVersion"></u-text>
<u-text :text="'下载次数:' + (item.downloadCount || 0)"></u-text>
</u-row>
</u-col>
</u-row>
</template>
</view>
</template>
<script>
export default {
data() {
return{
baseUrl: uni.$u.http.config.baseURL,
loading: true,
appList: [],
recommendList: [],
installedAppList: [],
downloadingAppIds: [],
keyword: '',
active: 0
}
},
onShow(){
this.getApplicationMarketList()
},
created() {
this.getApplicationMarketList()
},
methods: {
getAppList(){
return new Promise((resolve , reject) => {
// #ifdef APP-PLUS
plus.android.importClass('java.util.ArrayList')
plus.android.importClass('android.content.pm.PackageInfo')
plus.android.importClass('android.content.pm.PackageManager')
let MainActivity = plus.android.runtimeMainActivity()
let PackageManager = MainActivity.getPackageManager()
let pinfo = plus.android.invoke(PackageManager , 'getInstalledPackages' , 0)
if(pinfo != null){
let apklist = []
for(let i = 0; i < pinfo.size(); i++){
let pkginfo = pinfo.get(i)
let issysapk = ((pkginfo.plusGetAttribute('applicationInfo').plusGetAttribute(
'flags') & plus.android.importClass('android.content.pm.ApplicationInfo')
.FLAG_SYSTEM) != 0) ? true : false
if(issysapk == false){
const apkinfo = {
packageName: pkginfo.plusGetAttribute('packageName'),
versionName: pkginfo.plusGetAttribute('versionName')
}
apklist.push(apkinfo)
}
}
resolve(apklist)
}else{
reject([])
}
// #endif
// #ifndef APP-PLUS
resolve([])
// #endif
})
},
async getApplicationMarketList(){
this.loading = true
this.installedAppList = await this.getAppList()
uni.$u.http.get('/control/app/list' , {params: {appName: this.keyword}}).then(res => {
this.appList = res.rows
}).then(() => {
if(this.active == 0){
this.recommendList = this.appList.filter(item => item.isRecommended).slice(0 , 3)
uni.$u.http.get('/control/topic/list').then(res => {
this.appList = res.rows[0].appList
})
}
if(this.active == 1 && this.installedAppList.length){
this.appList = this.appList.filter(item => {
const app = this.installedAppList.find(app => app.packageName === item.appPackageName)
if(app){
return item.appVersion > app.versionName
}
return false
})
}
})
this.loading = false
},
downAndInstallApp(path){
return new Promise((resolve , reject) => {
// #ifdef APP-PLUS
uni.showToast({
title: '开始下载',
icon: 'none'
})
uni.downloadFile({
url: `${this.baseUrl}${path}`,
success(result){
plus.runtime.install(result.tempFilePath , {force: true})
resolve(result.statusCode)
}
})
// #endif
// #ifndef APP-PLUS
uni.showToast({
title: '请在APP中打开',
icon: 'none'
})
// #endif
})
},
async handleDownload(item , status){
// #ifdef APP-PLUS
this.downloadingAppIds.push(item.id)
// #endif
const result = await this.downAndInstallApp(item.appUrl)
if(result == 200){
this.downloadingAppIds = this.downloadingAppIds.filter(id => id !== item.id)
uni.$u.http.post('/control/record' , {appIds: item.id}).then(() => {
this.getApplicationMarketList()
})
if(status == '更新'){
await uni.$u.http.put(`/control/app?id=${item.id}&appVersion=${parseFloat(item.appVersion) + 0.01}`)
}
}
},
getAppList(item , installedAppList , color = false){
const app = installedAppList.find(app => app.packageName === item.appPackageName)
if(app){
if(color){
return item.appVersion > app.versionName ? 'blue' : 'gray'
}
return item.appVersion > app.versionName ? '更新' : '已安装'
}
if(color){
return 'black'
}
return '下载'
},
tabChange(index){
this.active = index
this.appList = []
this.getApplicationMarketList()
}
}
}
</script>
<style>
</style>请对比两段代码的不同,我不希望也拒绝你的修改,只需要帮我找出两段代码不一样并导致bug的地方,不要找一些无关紧要的样式不同
最新发布