2 lines
8.5 KiB
JavaScript
2 lines
8.5 KiB
JavaScript
var e,t=Object.defineProperty,r=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,c=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,o=(e,t)=>{for(var r in t||(t={}))s.call(t,r)&&c(e,r,t[r]);if(i)for(var r of i(t))a.call(t,r)&&c(e,r,t[r]);return e},u=(e,t)=>r(e,n(t)),d=(e,t,r)=>new Promise((n,i)=>{var s=e=>{try{c(r.next(e))}catch(t){i(t)}},a=e=>{try{c(r.throw(e))}catch(t){i(t)}},c=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);c((r=r.apply(e,t)).next())});import{B as l,i as p,E as h}from"./index-DcUr69Kn.js";const y=null==(e={baseUrl:"/api"})?void 0:e.baseUrl,m=[{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}],g=[{id:"1",name:"管理员",phone:"13800138000",role:"admin",createTime:"2024-01-01"},{id:"2",name:"回收员小王",phone:"18698102228",role:"collector",createTime:"2024-01-15"}],f=(e,...t)=>d(void 0,[e,...t],function*(e,t={}){const r=y+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)}):l({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)}})})}),O={getPrices(){return d(this,null,function*(){try{console.log("Fetching prices from:",y+"/prices");const e=yield f("/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:m}}})},addPrice(e){return d(this,null,function*(){try{return(yield f("/prices",{method:"POST",data:e})).success}catch(t){const r=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:m};return r.prices.push(e),h("api_prices",r),!0}})},updatePrice(e,t){return d(this,null,function*(){try{const r=t||e.category;return(yield f(`/prices/${r}`,{method:"PUT",data:e})).success}catch(r){const n=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:m},i=t||e.category,s=n.prices.findIndex(e=>e.category===i);return s>-1&&(n.prices[s]=e,h("api_prices",n)),!0}})},deletePrice(e){return d(this,null,function*(){try{return(yield f(`/prices/${e}`,{method:"DELETE"})).success}catch(t){const r=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:m};return r.prices=r.prices.filter(t=>t.category!==e),h("api_prices",r),!0}})}},v={getOrders(){return d(this,null,function*(){try{return(yield f("/orders")).data||[]}catch(e){return p("api_orders")||[]}})},addOrder(e){return d(this,null,function*(){try{return(yield f("/orders",{method:"POST",data:e})).order||null}catch(t){const r=p("api_orders")||[],n=u(o({},e),{id:Date.now().toString(),createTime:(new Date).toISOString()});return r.unshift(n),h("api_orders",r),n}})},updateOrder(e){return d(this,null,function*(){try{return(yield f(`/orders/${e.id}`,{method:"PUT",data:e})).success}catch(t){const r=p("api_orders")||[],n=r.findIndex(t=>t.id===e.id);return n>-1&&(r[n]=e,h("api_orders",r)),!0}})},deleteOrder(e){return d(this,null,function*(){try{return(yield f(`/orders/${e}`,{method:"DELETE"})).success}catch(t){const r=(p("api_orders")||[]).filter(t=>t.id!==e);return h("api_orders",r),!0}})}},T={getUsers(){return d(this,null,function*(){try{return(yield f("/users")).data||[]}catch(e){return p("api_users")||g}})},addUser(e){return d(this,null,function*(){try{return(yield f("/users",{method:"POST",data:e})).success}catch(t){const r=p("api_users")||g,n=u(o({},e),{id:Date.now().toString(),createTime:(new Date).toISOString().split("T")[0]});return r.push(n),h("api_users",r),!0}})},updateUser(e){return d(this,null,function*(){try{return(yield f(`/users/${e.id}`,{method:"PUT",data:e})).success}catch(t){const r=p("api_users")||g,n=r.findIndex(t=>t.id===e.id);return n>-1&&(r[n]=e,h("api_users",r)),!0}})},deleteUser(e){return d(this,null,function*(){try{return(yield f(`/users/${e}`,{method:"DELETE"})).success}catch(t){const r=(p("api_users")||g).filter(t=>t.id!==e);return h("api_users",r),!0}})}},S={getCities(){return d(this,null,function*(){var e;try{return(null==(e=(yield f("/regions/cities")).data)?void 0:e.map(e=>e.name))||[]}catch(t){return["天津市","北京市","上海市","广州市"]}})},getDistricts(e){return d(this,null,function*(){var t;try{return(null==(t=(yield f("/regions/districts")).data)?void 0:t.filter(t=>t.cityName===e).map(e=>e.name))||[]}catch(r){return{"天津市":["高新区","西青区","保税区"],"北京市":["东城区","西城区","朝阳区","海淀区","丰台区"],"上海市":["黄浦区","徐汇区","浦东新区","静安区","长宁区"],"广州市":["天河区","海珠区","越秀区","白云区","荔湾区"]}[e]||[]}})},getStations(e,t){return d(this,null,function*(){var r,n;try{return(null==(r=(yield f("/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 d(this,null,function*(){var t;try{return(null==(t=(yield f("/regions/site-users")).data)?void 0:t.filter(t=>t.stationName===e).map(e=>e.name))||[]}catch(r){return[]}})},getCommunities(e,t){return d(this,null,function*(){var r;try{return(yield f(`/regions/communities?city=${encodeURIComponent(e)}&district=${encodeURIComponent(t)}`)).data||[]}catch(n){return(null==(r={"天津市":{"高新区":["金融街融汇景苑","金辉江山铭筑"],"西青区":["华兴里","华兴南里"],"保税区":["意境兰庭"]},"北京市":{"东城区":["景山街道","交道口街道","东四街道","朝阳门街道","建国门街道"],"西城区":["西长安街街道","新街口街道","月坛街道","展览路街道","德胜街道"],"朝阳区":["朝外街道","劲松街道","呼家楼街道","三里屯街道","团结湖街道"],"海淀区":["海淀街道","中关村街道","学院路街道","西三旗街道","清河街道"]},"上海市":{"黄浦区":["南京东路街道","外滩街道","瑞金二路街道","淮海中路街道","豫园街道"],"徐汇区":["天平路街道","湖南路街道","斜土路街道","枫林路街道","长桥街道"],"浦东新区":["陆家嘴街道","潍坊新村街道","塘桥街道","南码头路街道","周家渡街道"]},"广州市":{"天河区":["五山街道","员村街道","车陂街道","沙河街道","石牌街道"],"海珠区":["赤岗街道","新港街道","昌岗街道","江南中街道","滨江街道"],"越秀区":["洪桥街道","北京街道","六榕街道","流花街道","光塔街道"]}}[e])?void 0:r[t])||[]}})},addRegion(e,t,r){return d(this,null,function*(){try{return(yield f("/regions",{method:"POST",data:{city:e,district:t,community:r}})).success}catch(n){return!0}})}};export{v as o,O as p,S as r,T as u};
|