Files
huishou/dist/build/mp-weixin/api/index.js
T
2026-07-27 14:07:26 +08:00

2 lines
8.9 KiB
JavaScript

"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,c=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n,o=(e,t)=>{for(var r in t||(t={}))i.call(t,r)&&c(e,r,t[r]);if(n)for(var r of n(t))s.call(t,r)&&c(e,r,t[r]);return e},a=(e,n)=>t(e,r(n)),u=(e,t,r)=>new Promise((n,i)=>{var s=e=>{try{o(r.next(e))}catch(t){i(t)}},c=e=>{try{o(r.throw(e))}catch(t){i(t)}},o=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,c);o((r=r.apply(e,t)).next())});const d=require("../common/vendor.js"),l=require("../config/index.js"),p=[{category:"001",name:"纸类",unit:"kg",price:1.2},{category:"002",name:"金属",unit:"kg",price:2.5},{category:"003",name:"易拉罐",unit:"piece",price:.1},{category:"004",name:"塑料",unit:"kg",price:3},{category:"005",name:"织物",unit:"kg",price:.8},{category:"006",name:"塑料瓶",unit:"piece",price:.05}],y=[{id:"1",name:"管理员",phone:"13800138000",role:"admin",createTime:"2024-01-01"},{id:"2",name:"回收员小王",phone:"18698102228",role:"collector",createTime:"2024-01-15"}],g=(e,...t)=>u(exports,[e,...t],function*(e,t={}){const r=l.BASE_URL+e;return console.log("Request URL:",r),new Promise((e,n)=>{"undefined"!=typeof window?fetch(r,{method:t.method||"GET",headers:o({"Content-Type":"application/json"},t.header),body:t.data?JSON.stringify(t.data):void 0}).then(e=>{if(console.log("Response status:",e.status),e.ok)return e.json();throw new Error("Request failed with status "+e.status)}).then(t=>{console.log("Response data:",t),e(t)}).catch(e=>{console.error("Fetch failed:",e),n(e)}):d.index.request({url:r,method:t.method||"GET",data:t.data,header:o({"Content-Type":"application/json"},t.header),success:t=>{console.log("uni.request success:",t.statusCode,t.data),200===t.statusCode?e(t.data):n(new Error("请求失败"))},fail:e=>{console.error("API request failed, using mock data:",e),n(e)}})})}),h={getPrices(){return u(this,null,function*(){try{console.log("Fetching prices from:",l.BASE_URL+"/prices");const e=yield g("/prices");return console.log("Received prices:",e),e}catch(e){return console.error("API request failed, using mock data:",e),{date:(new Date).toISOString().split("T")[0],prices:p}}})},addPrice(e){return u(this,null,function*(){try{return(yield g("/prices",{method:"POST",data:e})).success}catch(t){const r=d.index.getStorageSync("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:p};return r.prices.push(e),d.index.setStorageSync("api_prices",r),!0}})},updatePrice(e,t){return u(this,null,function*(){try{const r=t||e.category;return(yield g(`/prices/${r}`,{method:"PUT",data:e})).success}catch(r){const n=d.index.getStorageSync("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:p},i=t||e.category,s=n.prices.findIndex(e=>e.category===i);return s>-1&&(n.prices[s]=e,d.index.setStorageSync("api_prices",n)),!0}})},deletePrice(e){return u(this,null,function*(){try{return(yield g(`/prices/${e}`,{method:"DELETE"})).success}catch(t){const r=d.index.getStorageSync("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:p};return r.prices=r.prices.filter(t=>t.category!==e),d.index.setStorageSync("api_prices",r),!0}})}},S={getOrders(){return u(this,null,function*(){try{return(yield g("/orders")).data||[]}catch(e){return d.index.getStorageSync("api_orders")||[]}})},addOrder(e){return u(this,null,function*(){try{return(yield g("/orders",{method:"POST",data:e})).order||null}catch(t){const r=d.index.getStorageSync("api_orders")||[],n=a(o({},e),{id:Date.now().toString(),createTime:(new Date).toISOString()});return r.unshift(n),d.index.setStorageSync("api_orders",r),n}})},updateOrder(e){return u(this,null,function*(){try{return(yield g(`/orders/${e.id}`,{method:"PUT",data:e})).success}catch(t){const r=d.index.getStorageSync("api_orders")||[],n=r.findIndex(t=>t.id===e.id);return n>-1&&(r[n]=e,d.index.setStorageSync("api_orders",r)),!0}})},deleteOrder(e){return u(this,null,function*(){try{return(yield g(`/orders/${e}`,{method:"DELETE"})).success}catch(t){const r=(d.index.getStorageSync("api_orders")||[]).filter(t=>t.id!==e);return d.index.setStorageSync("api_orders",r),!0}})}},m={getUsers(){return u(this,null,function*(){try{return(yield g("/users")).data||[]}catch(e){return d.index.getStorageSync("api_users")||y}})},addUser(e){return u(this,null,function*(){try{return(yield g("/users",{method:"POST",data:e})).success}catch(t){const r=d.index.getStorageSync("api_users")||y,n=a(o({},e),{id:Date.now().toString(),createTime:(new Date).toISOString().split("T")[0]});return r.push(n),d.index.setStorageSync("api_users",r),!0}})},updateUser(e){return u(this,null,function*(){try{return(yield g(`/users/${e.id}`,{method:"PUT",data:e})).success}catch(t){const r=d.index.getStorageSync("api_users")||y,n=r.findIndex(t=>t.id===e.id);return n>-1&&(r[n]=e,d.index.setStorageSync("api_users",r)),!0}})},deleteUser(e){return u(this,null,function*(){try{return(yield g(`/users/${e}`,{method:"DELETE"})).success}catch(t){const r=(d.index.getStorageSync("api_users")||y).filter(t=>t.id!==e);return d.index.setStorageSync("api_users",r),!0}})}},f={getCities(){return u(this,null,function*(){var e;try{return(null==(e=(yield g("/regions/cities")).data)?void 0:e.map(e=>e.name))||[]}catch(t){return["天津市","北京市","上海市","广州市"]}})},getDistricts(e){return u(this,null,function*(){var t;try{return(null==(t=(yield g("/regions/districts")).data)?void 0:t.filter(t=>t.cityName===e).map(e=>e.name))||[]}catch(r){return{"天津市":["高新区","西青区","保税区"],"北京市":["东城区","西城区","朝阳区","海淀区","丰台区"],"上海市":["黄浦区","徐汇区","浦东新区","静安区","长宁区"],"广州市":["天河区","海珠区","越秀区","白云区","荔湾区"]}[e]||[]}})},getStations(e,t){return u(this,null,function*(){var r,n;try{return(null==(r=(yield g("/regions/stations")).data)?void 0:r.filter(r=>r.cityName===e&&r.districtName===t).map(e=>e.name))||[]}catch(i){return(null==(n={"天津市":{"高新区":["金融街融汇景苑","金辉江山铭筑"],"西青区":["华兴里","华兴南里"],"保税区":["意境兰庭"]},"北京市":{"东城区":["景山街道","交道口街道","东四街道","朝阳门街道","建国门街道"],"西城区":["西长安街街道","新街口街道","月坛街道","展览路街道","德胜街道"],"朝阳区":["朝外街道","劲松街道","呼家楼街道","三里屯街道","团结湖街道"],"海淀区":["海淀街道","中关村街道","学院路街道","西三旗街道","清河街道"]},"上海市":{"黄浦区":["南京东路街道","外滩街道","瑞金二路街道","淮海中路街道","豫园街道"],"徐汇区":["天平路街道","湖南路街道","斜土路街道","枫林路街道","长桥街道"],"浦东新区":["陆家嘴街道","潍坊新村街道","塘桥街道","南码头路街道","周家渡街道"]},"广州市":{"天河区":["五山街道","员村街道","车陂街道","沙河街道","石牌街道"],"海珠区":["赤岗街道","新港街道","昌岗街道","江南中街道","滨江街道"],"越秀区":["洪桥街道","北京街道","六榕街道","流花街道","光塔街道"]}}[e])?void 0:n[t])||[]}})},getSiteUsers(e){return u(this,null,function*(){var t;try{return(null==(t=(yield g("/regions/site-users")).data)?void 0:t.filter(t=>t.stationName===e).map(e=>e.name))||[]}catch(r){return[]}})},getCommunities(e,t){return u(this,null,function*(){var r;try{return(yield g(`/regions/communities?city=${encodeURIComponent(e)}&district=${encodeURIComponent(t)}`)).data||[]}catch(n){return(null==(r={"天津市":{"高新区":["金融街融汇景苑","金辉江山铭筑"],"西青区":["华兴里","华兴南里"],"保税区":["意境兰庭"]},"北京市":{"东城区":["景山街道","交道口街道","东四街道","朝阳门街道","建国门街道"],"西城区":["西长安街街道","新街口街道","月坛街道","展览路街道","德胜街道"],"朝阳区":["朝外街道","劲松街道","呼家楼街道","三里屯街道","团结湖街道"],"海淀区":["海淀街道","中关村街道","学院路街道","西三旗街道","清河街道"]},"上海市":{"黄浦区":["南京东路街道","外滩街道","瑞金二路街道","淮海中路街道","豫园街道"],"徐汇区":["天平路街道","湖南路街道","斜土路街道","枫林路街道","长桥街道"],"浦东新区":["陆家嘴街道","潍坊新村街道","塘桥街道","南码头路街道","周家渡街道"]},"广州市":{"天河区":["五山街道","员村街道","车陂街道","沙河街道","石牌街道"],"海珠区":["赤岗街道","新港街道","昌岗街道","江南中街道","滨江街道"],"越秀区":["洪桥街道","北京街道","六榕街道","流花街道","光塔街道"]}}[e])?void 0:r[t])||[]}})},addRegion(e,t,r){return u(this,null,function*(){try{return(yield g("/regions",{method:"POST",data:{city:e,district:t,community:r}})).success}catch(n){return!0}})}};exports.orderApi=S,exports.priceApi=h,exports.regionApi=f,exports.userApi=m;