box_app: serve mama-box at /mama-box/ (align with mp.yizhezhe.com subdirectory apps); mount /mama-box, drop /apps+/assets; _img_url & init_mamabox URL → /mama-box/
BIN
assets/img/02cf420f0d07.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/img/056212807d86.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/img/0ebc7631fea4.png
Normal file
|
After Width: | Height: | Size: 743 B |
BIN
assets/img/1afd85e578dd.png
Normal file
|
After Width: | Height: | Size: 813 B |
BIN
assets/img/2d23b079caca.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
assets/img/30de43bbc9aa.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/img/3657b1f76026.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
assets/img/4657f50f42c8.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
assets/img/505ace532176.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/img/67405412c52c.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/img/69818ea975da.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
assets/img/72910df66ee3.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/img/72f41378ef8e.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/img/7980160b80b0.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
assets/img/7b7d81e02f42.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
assets/img/8b0f0a53938b.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
assets/img/949338312a1f.png
Normal file
|
After Width: | Height: | Size: 869 B |
BIN
assets/img/97c33531806b.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/img/9a2e7fa472dc.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/img/9f3fa8edf4aa.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
assets/img/a9e3b27a4a23.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/img/b00c707f7b1f.png
Normal file
|
After Width: | Height: | Size: 165 KiB |
BIN
assets/img/b2066fd752bf.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
assets/img/b855b45df1f3.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/img/c2ae6e98283b.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/img/dd5639fde61d.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/img/de0bc9e250f2.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/img/df905dcf3a1c.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
assets/img/f0d5e062f11a.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
assets/img/f34fb7fdeea5.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/img/f989a64fe960.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
assets/img/fa7b793b47e8.png
Normal file
|
After Width: | Height: | Size: 699 B |
BIN
assets/img/fd875eb78785.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/resources/book.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
assets/resources/diet.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/resources/food.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
assets/resources/med.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
assets/resources/music.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/resources/report.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
assets/resources/sleep.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
assets/resources/sport.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
1719
index.html
Normal file
88
js/core.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/* 妈妈盒子 · MPA 共享层(无框架,普通 <script>,兼容微信 webview)
|
||||
window.MB:openid 解析、带 openid 的 fetch、hash 深链、缓存、UI 工具 */
|
||||
(function (global) {
|
||||
'use strict';
|
||||
var API = '/api/mp/public/mama-box';
|
||||
|
||||
function readHash(name) {
|
||||
try {
|
||||
var h = location.hash.slice(1);
|
||||
var m = h.match(new RegExp('(?:^|&)' + name + '=([^&]*)'));
|
||||
if (m) return decodeURIComponent(m[1]);
|
||||
m = location.search.match(new RegExp('[?&]' + name + '=([^&]*)'));
|
||||
if (m) return decodeURIComponent(m[1]);
|
||||
} catch (e) {}
|
||||
return '';
|
||||
}
|
||||
|
||||
var MB = {
|
||||
openid: function () { return readHash('openid'); },
|
||||
param: readHash,
|
||||
|
||||
/* 拼 hash 深链:page.html#openid=x&key=...(微信 webview 内 hash 不丢) */
|
||||
buildUrl: function (page, params) {
|
||||
var parts = [];
|
||||
var oid = MB.openid();
|
||||
if (oid) parts.push('openid=' + encodeURIComponent(oid));
|
||||
var p = params || {};
|
||||
Object.keys(p).forEach(function (k) { parts.push(k + '=' + encodeURIComponent(p[k])); });
|
||||
return page + '.html' + (parts.length ? '#' + parts.join('&') : '');
|
||||
},
|
||||
go: function (page, params) { location.href = MB.buildUrl(page, params); },
|
||||
|
||||
/* 带 openid 的 GET,解包 {code,message,result} → result 或 null(失败回退) */
|
||||
fetch: function (path, params) {
|
||||
var oid = MB.openid();
|
||||
var qs = [];
|
||||
var p = params || {};
|
||||
Object.keys(p).forEach(function (k) { qs.push(k + '=' + encodeURIComponent(p[k])); });
|
||||
if (oid) qs.push('openid=' + encodeURIComponent(oid));
|
||||
var url = API + path + (qs.length ? '?' + qs.join('&') : '');
|
||||
return fetch(url)
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (j) { return (j && j.code === 200) ? j.result : null; })
|
||||
.catch(function () { return null; });
|
||||
},
|
||||
get: function (path, params) { return MB.fetch(path, params); },
|
||||
|
||||
/* 内存缓存(同一页内避免重复请求) */
|
||||
cache: {},
|
||||
cached: function (key, fn) {
|
||||
if (key in MB.cache) return Promise.resolve(MB.cache[key]);
|
||||
return fn().then(function (v) { MB.cache[key] = v; return v; });
|
||||
},
|
||||
pregnancy: function () { return MB.cached('pregnancy', function () { return MB.fetch('/pregnancy'); }); },
|
||||
profile: function () { return MB.cached('profile', function () { return MB.fetch('/profile'); }); },
|
||||
|
||||
/* UI 工具 */
|
||||
toast: function (msg) {
|
||||
var t = document.getElementById('toast');
|
||||
if (!t) return;
|
||||
t.textContent = msg; t.classList.add('show');
|
||||
clearTimeout(MB._tt); MB._tt = setTimeout(function () { t.classList.remove('show'); }, 1800);
|
||||
},
|
||||
haptic: function () { if (navigator.vibrate) navigator.vibrate(8); },
|
||||
ripple: function (ev) {
|
||||
var t = ev.target.closest('.ripple');
|
||||
if (!t) return;
|
||||
var r = t.getBoundingClientRect();
|
||||
var size = Math.max(r.width, r.height) * 2.1;
|
||||
var sp = document.createElement('span');
|
||||
sp.className = 'rp';
|
||||
sp.style.cssText = 'width:' + size + 'px;height:' + size + 'px;left:' + (ev.clientX - r.left) + 'px;top:' + (ev.clientY - r.top) + 'px';
|
||||
t.appendChild(sp); setTimeout(function () { sp.remove(); }, 600);
|
||||
},
|
||||
|
||||
/* 孕周/日期工具(对齐原型) */
|
||||
WEEK: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
|
||||
weekTxt: function (week, day) {
|
||||
return '孕 ' + week + ' 周' + (day ? ' +' + day + ' 天' : '');
|
||||
},
|
||||
fmtFull: function (ms) {
|
||||
var d = new Date(ms);
|
||||
return d.getFullYear() + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日';
|
||||
}
|
||||
};
|
||||
|
||||
global.MB = MB;
|
||||
})(window);
|
||||