1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

小程序端审核隐藏功能通过传参指定

This commit is contained in:
2023-04-26 01:01:18 +08:00
parent d96fd3d536
commit 2d145793b4
4 changed files with 138 additions and 98 deletions

View File

@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Dev-Gateway (epp.miniprogram.config=hide)" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<envs>
<env name="--spring.profiles.active" value="develop" />
</envs>
<module name="microservice-gateway" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.gateway.Gateway" />
<option name="VM_PARAMETERS" value="-Xms64m -Xmx256m -Depp.miniprogram.config=hide" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.cxyxiaomo.epp.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -1,10 +1,13 @@
package com.cxyxiaomo.epp.gateway.controller; package com.cxyxiaomo.epp.gateway.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects;
@RestController @RestController
public class Controller { public class Controller {
@@ -14,17 +17,29 @@ public class Controller {
return "[ERROR] 500 Internal Server Error"; return "[ERROR] 500 Internal Server Error";
} }
@Value("${epp.miniprogram.config}")
private String miniprogramConfig;
/** /**
* 为了通过微信的小程序审核所特别处理的 * 为了通过微信的小程序审核所特别处理的
* *
* @return * @return
*/ */
@RequestMapping("/getConfig") @RequestMapping("/getConfig")
public HashMap<String, Object> WxMiniProgramAuditSpecialHandle() { public HashMap<String, Object> WxMiniProgramAuditSpecialHandle(@RequestParam(value = "v", required = false) String version) {
boolean showCode = true; boolean showCode = true;
boolean showShop = true; boolean showShop = true;
boolean showReport = true; boolean showReport = true;
// 第一版提审,已通过,在线上 version == null
if (version.equals("2")) {
// 第一版提审,按照配置文件中的配置来
if (Objects.equals(miniprogramConfig, "hide")) {
showCode = false;
showShop = false;
}
}
// 底部 tabbar // 底部 tabbar
LinkedList<String> tabbarItem = new LinkedList<>(); LinkedList<String> tabbarItem = new LinkedList<>();
tabbarItem.push("pages/index/index"); tabbarItem.push("pages/index/index");

View File

@@ -97,3 +97,9 @@ spring:
args: args:
status: 302 status: 302
url: https://www.baidu.com/?wd= url: https://www.baidu.com/?wd=
epp:
miniprogram:
# 为了通过微信的小程序审核所特别处理的
# show / hide
config: show

View File

@@ -1,97 +1,97 @@
var defaultTabbarItem = [ var defaultTabbarItem = [
"pages/person/person", "pages/person/person",
"pages/residents/report", "pages/residents/report",
"pages/index/index" "pages/index/index"
] ]
export function toggle(that) { export function toggle(that) {
let pages = getCurrentPages() let pages = getCurrentPages()
let route = pages[pages.length - 1].route let route = pages[pages.length - 1].route
console.log("[CustomTabBar] route", route) console.log("[CustomTabBar] route", route)
if (!typeof that.getTabBar === 'function' || !that.getTabBar()) { if (!typeof that.getTabBar === 'function' || !that.getTabBar()) {
// wx.showModal({ // wx.showModal({
// title: '版本太旧', // title: '版本太旧',
// content: '您的微信版本太旧,无法使用本小程序', // content: '您的微信版本太旧,无法使用本小程序',
// showCancel: false, // showCancel: false,
// complete: (res) => { // complete: (res) => {
// wx.exitMiniProgram() // wx.exitMiniProgram()
// } // }
// }) // })
return return
} }
// 找出要选择哪一项 // 找出要选择哪一项
let tabBar = that.getTabBar() let tabBar = that.getTabBar()
console.log("[CustomTabBar] tabBar", tabBar) console.log("[CustomTabBar] tabBar", tabBar)
let data = tabBar.data let data = tabBar.data
console.log("[CustomTabBar] data", data) console.log("[CustomTabBar] data", data)
let showPagePathList = wx.getStorageSync('tabbarItem') || defaultTabbarItem let showPagePathList = wx.getStorageSync('tabbarItem') || defaultTabbarItem
console.log("[CustomTabBar] showPagePathList", showPagePathList) console.log("[CustomTabBar] showPagePathList", showPagePathList)
let list = tabBar.data.rawList.filter((page) => showPagePathList.includes(page.pagePath)) let list = tabBar.data.rawList.filter((page) => showPagePathList.includes(page.pagePath))
console.log("[CustomTabBar] tabBarList", list) console.log("[CustomTabBar] tabBarList", list)
let selected = list ? list.indexOf(list.find(p => p.pagePath == route)) : -1 let selected = list ? list.indexOf(list.find(p => p.pagePath == route)) : -1
console.log("[CustomTabBar] selected", selected) console.log("[CustomTabBar] selected", selected)
console.log("更新tabbar") console.log("更新tabbar")
// 选中这一项 // 选中这一项
tabBar.setData({ tabBar.setData({
selected: selected, selected: selected,
list: list list: list
}) })
} }
export function updateConfig(baseUrl) { export function updateConfig(baseUrl) {
// 请求配置文件(用于审核时隐藏部分功能) // 请求配置文件(用于审核时隐藏部分功能)
wx.request({ wx.request({
url: baseUrl + '/getConfig', url: baseUrl + '/getConfig?v=2',
success(result) { success(result) {
let data = result.data let data = result.data
if (data.tabbarItem) { if (data.tabbarItem) {
console.log("[CustomTabBar] tabbar数据拉取完毕") console.log("[CustomTabBar] tabbar数据拉取完毕")
wx.setStorageSync('tabbarItem', data.tabbarItem) wx.setStorageSync('tabbarItem', data.tabbarItem)
wx.setStorageSync('indexItem', data.indexItem) wx.setStorageSync('indexItem', data.indexItem)
const pages = getCurrentPages(); const pages = getCurrentPages();
const indexPage = pages[0] const indexPage = pages[0]
const currentPage = pages[pages.length - 1] const currentPage = pages[pages.length - 1]
console.log("[CustomTabBar] indexPage", indexPage) console.log("[CustomTabBar] indexPage", indexPage)
console.log("[CustomTabBar] currentPage", currentPage) console.log("[CustomTabBar] currentPage", currentPage)
// // 更新tabbar // // 更新tabbar
// toggle(currentPage) // toggle(currentPage)
// 刷新首页中包含了触发 toggle 的代码 此处不重复触发 // 刷新首页中包含了触发 toggle 的代码 此处不重复触发
// 刷新首页 // 刷新首页
indexPage && indexPage.onLoad() indexPage && indexPage.onLoad()
// let tabBar = currentPage.getTabBar() // let tabBar = currentPage.getTabBar()
// tabBar.setData({ // tabBar.setData({
// list: tabBar.data.rawList.filter((page) => itemList.includes(page.pagePath)) // list: tabBar.data.rawList.filter((page) => itemList.includes(page.pagePath))
// }) // })
} }
}, },
fail() { fail() {
wx.showModal({ wx.showModal({
title: '小程序启动失败', title: '小程序启动失败',
content: '点击确认重试,若多次失败请检查网络连接', content: '点击确认重试,若多次失败请检查网络连接',
complete: (res) => { complete: (res) => {
if (res.cancel) { if (res.cancel) {
wx.exitMiniProgram() wx.exitMiniProgram()
} }
if (res.confirm) { if (res.confirm) {
wx.reLaunch({ wx.reLaunch({
url: 'pages/index/index', url: 'pages/index/index',
}) })
} }
} }
}) })
} }
}) })
} }