配置修改

This commit is contained in:
2026-07-13 16:33:09 +08:00
parent 9998f4651b
commit d1a15a4c42
15 changed files with 348 additions and 38 deletions

View File

@ -0,0 +1,71 @@
/**
* 茶址商城:小程序入口城市逻辑补丁
* 将定位切换城市改为:直达=上海总部,扫码=码主人城市
*/
const fs = require('fs');
const path = require('path');
const root = path.join(__dirname, '..');
function patch(file, replacements) {
const filePath = path.join(root, file);
let content = fs.readFileSync(filePath, 'utf8');
let changed = 0;
for (const [oldStr, newStr] of replacements) {
if (!content.includes(oldStr)) {
console.error(`[MISS] ${file}: pattern not found`);
console.error(oldStr.slice(0, 120) + '...');
continue;
}
content = content.replace(oldStr, newStr);
changed++;
}
fs.writeFileSync(filePath, content, 'utf8');
console.log(`[OK] ${file}: ${changed} replacements`);
}
// 1. vendor.js - 新增 getEntryCity API
patch('public/mp-weixin/common/vendor.js', [
[
't.getGeocoder=function(e){return n.default.get("index/geocoder",{params:e})}',
't.getGeocoder=function(e){return n.default.get("index/geocoder",{params:e})},t.getEntryCity=function(e){return n.default.get("index/getEntryCity",{params:e})}'
],
[
'initLocationFunc:function(t){return(0,i.default)(n.default.mark((function a(){var l,r,i,u,s,c;return n.default.wrap((function(a){while(1)switch(a.prev=a.next){case 0:return l=t.dispatch,r=t.rootState,console.log("获取地址"),a.prev=2,a.next=5,e.getLocation({type:"gcj02"});case 5:if(i=a.sent,u=(0,o.default)(i,2),s=u[0],c=u[1],console.log(s,c,"----"),l("getSystemInfo"),r.app.sysInfo.locationEnabled){a.next=14;break}return e.showModal({title:"温馨提示",content:"您的手机定位还未开启"}),a.abrupt("return");case 14:if(c){a.next=16;break}return a.abrupt("return",l("getAuthorize"));case 16:if(!s){a.next=19;break}return e.showModal({title:"温馨提示",content:"获取位置失败,请检查是否开启定位!"}),a.abrupt("return");case 19:l("getGeocoderFunc",{location:"".concat(c.latitude,",").concat(c.longitude)}),a.next=25;break;case 22:a.prev=22,a.t0=a["catch"](2),console.log(a.t0);case 25:case"end":return a.stop()}}),a,null,[[2,22]])})))()}',
'initLocationFunc:function(t){return(0,i.default)(n.default.mark((function a(){var l,r,u,c,v;return n.default.wrap((function(a){while(1)switch(a.prev=a.next){case 0:return l=t.commit,a.prev=1,u={},a.prev=2,c=e.getStorageSync("ENTRY_CITY_PARAMS"),c&&(u=JSON.parse(c)),a.next=7,(0,s.getEntryCity)(u);case 7:if(v=a.sent,1!=v.code){a.next=11;break}r=v.data,l("setCityInfo",{id:r.id,name:r.name,gcj02_lat:r.gcj02_lat||0,gcj02_lng:r.gcj02_lng||0}),a.next=12;break;case 11:l("setCityInfo",{id:0,name:"上海总部",gcj02_lat:0,gcj02_lng:0});case 12:a.next=17;break;case 14:a.prev=14,a.t0=a["catch"](2),console.log(a.t0),l("setCityInfo",{id:0,name:"上海总部",gcj02_lat:0,gcj02_lng:0});case 17:case"end":return a.stop()}}),a,null,[[2,14],[1,14]])})))()}'
]
]);
// 2. main.js - onLaunch 解析扫码参数并初始化城市
patch('public/mp-weixin/common/main.js', [
[
'onLaunch:function(e){this.getConfigFun(),this.getSystemInfo(),this.getUser(),this.checkMpUpdate()}',
'onLaunch:function(e){this.initEntryCityFun(e),this.getConfigFun(),this.getSystemInfo(),this.getUser(),this.checkMpUpdate()}'
],
[
'(0,u.mapActions)(["getSystemInfo","getUser","initLocationFunc"])),(0,u.mapMutations)(["setConfig"])',
'(0,u.mapActions)(["getSystemInfo","getUser","initLocationFunc"])),(0,u.mapMutations)(["setConfig","setCityInfo"])'
],
[
'getConfigFun:function(){var e=this;return(0,c.default)(o.default.mark((function t(){var n,r,c;return o.default.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,(0,i.getConfig)();',
'initEntryCityFun:function(t){var n={};if(t&&t.query){t.query.invite_code&&(n.invite_code=t.query.invite_code);if(t.query.scene){var r=(0,f.strToParams)(decodeURIComponent(t.query.scene));r.invite_code&&(n.invite_code=r.invite_code);r.user_id&&(n.user_id=r.user_id)}t.query.user_id&&(n.user_id=t.query.user_id)}e.setStorageSync("ENTRY_CITY_PARAMS",JSON.stringify(n));this.initLocationFunc()},getConfigFun:function(){var e=this;return(0,c.default)(o.default.mark((function t(){var n,r,c;return o.default.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,(0,i.getConfig)();'
]
]);
// 3. privacy-popup.js - 同意隐私协议后初始化城市(不再依赖定位开关)
patch('public/mp-weixin/components/privacy-popup/privacy-popup.js', [
[
'handleAgreePrivacyAuthorization:function(){this.$emit("input",!1),this.appConfig.is_open_nearby&&this.initLocationFunc()}',
'handleAgreePrivacyAuthorization:function(){this.$emit("input",!1),this.initLocationFunc()}'
]
]);
// 4. index.js - 网络重试时初始化城市(不再走定位)
patch('public/mp-weixin/pages/index/index.js', [
[
'1==o&&(e.setConfig(r),r.is_open_nearby&&e.initLocationFunc()),e.getUser()',
'1==o&&(e.setConfig(r),e.initLocationFunc()),e.getUser()'
]
]);
console.log('Patch complete.');