2 lines
9.9 KiB
JavaScript
2 lines
9.9 KiB
JavaScript
var e,t=Object.defineProperty,r=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,a=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,c=(e,t)=>{for(var r in t||(t={}))s.call(t,r)&&a(e,r,t[r]);if(i)for(var r of i(t))o.call(t,r)&&a(e,r,t[r]);return e},u=(e,t)=>r(e,n(t)),l=(e,t,r)=>new Promise((n,i)=>{var s=e=>{try{a(r.next(e))}catch(t){i(t)}},o=e=>{try{a(r.throw(e))}catch(t){i(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,o);a((r=r.apply(e,t)).next())});import{A as d,i as p,B as h,y}from"./index-B5v3elQl.js";const m=null==(e={baseUrl:"/api"})?void 0:e.baseUrl,g=[{category:"001",name:"纸类(书本)",unit:"kg",price:1.2,icon:"paper"},{category:"002",name:"纸类(纸板)",unit:"kg",price:1,icon:"paper"},{category:"003",name:"金属(铜)",unit:"kg",price:25,icon:"metal"},{category:"004",name:"金属(铁)",unit:"kg",price:2.5,icon:"metal"},{category:"005",name:"金属(铝)",unit:"kg",price:8,icon:"metal"},{category:"006",name:"金属(其他)",unit:"kg",price:3,icon:"metal"},{category:"007",name:"塑料(瓶子)",unit:"kg",price:.5,icon:"plastic"},{category:"008",name:"塑料(其他)",unit:"kg",price:3,icon:"plastic"},{category:"009",name:"织物",unit:"kg",price:.8,icon:"fabric"},{category:"010",name:"玻璃",unit:"kg",price:.3,icon:"glass"}],f=[{id:"1",name:"管理员",phone:"13800138000",role:"admin",createTime:"2024-01-01"},{id:"2",name:"回收员小王",phone:"18698102228",role:"collector",createTime:"2024-01-15"}],O=(e,...t)=>l(void 0,[e,...t],function*(e,t={}){const r=m+e;return console.log("=== API Request ==="),console.log("URL:",r),console.log("Method:",t.method||"GET"),console.log("Data:",t.data),new Promise((e,n)=>{"undefined"!=typeof window?fetch(r,{method:t.method||"GET",headers:c({"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({url:r,method:t.method||"GET",data:t.data,header:c({"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)}})})}),S={getPrices(){return l(this,null,function*(){try{console.log("Fetching prices from:",m+"/prices");const e=yield O("/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:g}}})},addPrice(e){return l(this,null,function*(){try{return(yield O("/prices",{method:"POST",data:e})).success}catch(t){const r=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:g};return r.prices.push(e),h("api_prices",r),!0}})},updatePrice(e,t){return l(this,null,function*(){try{const r=t||e.category;return(yield O(`/prices/${r}`,{method:"PUT",data:e})).success}catch(r){const n=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:g},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 l(this,null,function*(){try{return(yield O(`/prices/${e}`,{method:"DELETE"})).success}catch(t){const r=p("api_prices")||{date:(new Date).toISOString().split("T")[0],prices:g};return r.prices=r.prices.filter(t=>t.category!==e),h("api_prices",r),!0}})}},T={getOrders(e){return l(this,null,function*(){try{const t=e?`/orders?collector=${e}`:"/orders";return(yield O(t)).data||[]}catch(t){const r=p("api_orders")||[];return e?r.filter(t=>t.collector===e):r}})},addOrder(e){return l(this,null,function*(){try{return(yield O("/orders",{method:"POST",data:e})).order||null}catch(t){const r=p("api_orders")||[],n=u(c({},e),{id:Date.now().toString(),createTime:(new Date).toISOString()});return r.unshift(n),h("api_orders",r),n}})},updateOrder(e){return l(this,null,function*(){try{return(yield O(`/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 l(this,null,function*(){try{return(yield O(`/orders/${e}`,{method:"DELETE"})).success}catch(t){const r=(p("api_orders")||[]).filter(t=>t.id!==e);return h("api_orders",r),!0}})}},P={getUsers(){return l(this,null,function*(){try{return(yield O("/users")).data||[]}catch(e){return p("api_users")||f}})},addUser(e){return l(this,null,function*(){try{return(yield O("/users",{method:"POST",data:e})).success}catch(t){const r=p("api_users")||f,n=u(c({},e),{id:Date.now().toString(),createTime:(new Date).toISOString().split("T")[0]});return r.push(n),h("api_users",r),!0}})},updateUser(e){return l(this,null,function*(){try{return(yield O(`/users/${e.id}`,{method:"PUT",data:e})).success}catch(t){const r=p("api_users")||f,n=r.findIndex(t=>t.id===e.id);return n>-1&&(r[n]=e,h("api_users",r)),!0}})},deleteUser(e){return l(this,null,function*(){try{return(yield O(`/users/${e}`,{method:"DELETE"})).success}catch(t){const r=(p("api_users")||f).filter(t=>t.id!==e);return h("api_users",r),!0}})}},v={login(e,t){return l(this,null,function*(){try{const r=yield O("/admin/login",{method:"POST",data:{phone:e,password:t}});return r.success&&h("admin_login",!0),r}catch(r){return"13800138000"===e&&"123456"===t?(h("admin_login",!0),{success:!0,message:"登录成功"}):{success:!1,message:"手机号或密码错误"}}})},logout(){return l(this,null,function*(){try{yield O("/auth/logout",{method:"POST"})}catch(e){console.log("Logout API failed, clearing local storage")}y("admin_login")})}},_={getCities(){return l(this,null,function*(){var e;try{return(null==(e=(yield O("/regions/cities")).data)?void 0:e.map(e=>e.name))||[]}catch(t){return["天津市","北京市","上海市","广州市"]}})},getDistricts(e){return l(this,null,function*(){var t;try{return(null==(t=(yield O("/regions/districts")).data)?void 0:t.filter(t=>t.cityName===e).map(e=>e.name))||[]}catch(r){return{"天津市":["高新区","西青区","保税区"],"北京市":["东城区","西城区","朝阳区","海淀区","丰台区"],"上海市":["黄浦区","徐汇区","浦东新区","静安区","长宁区"],"广州市":["天河区","海珠区","越秀区","白云区","荔湾区"]}[e]||[]}})},getStations(e,t){return l(this,null,function*(){var r,n;try{return(null==(r=(yield O("/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 l(this,null,function*(){var t;try{return(null==(t=(yield O("/regions/site-users")).data)?void 0:t.filter(t=>t.stationName===e).map(e=>e.name))||[]}catch(r){return[]}})},getStationByName(e){return l(this,null,function*(){try{const t=yield O(`/regions/station-by-name?name=${encodeURIComponent(e)}`);return t.success&&t.data?t.data:null}catch(t){return null}})},addSiteUser(e,t,r){return l(this,null,function*(){try{return(yield O("/regions/site-users",{method:"POST",data:{stationId:e,name:t,type:r}})).success}catch(n){return!1}})},getCommunities(e,t){return l(this,null,function*(){var r;try{return(yield O(`/regions/communities?city=${encodeURIComponent(e)}&district=${encodeURIComponent(t)}`)).data||[]}catch(n){return(null==(r={"天津市":{"高新区":["金融街融汇景苑","金辉江山铭筑"],"西青区":["华兴里","华兴南里"],"保税区":["意境兰庭"]},"北京市":{"东城区":["景山街道","交道口街道","东四街道","朝阳门街道","建国门街道"],"西城区":["西长安街街道","新街口街道","月坛街道","展览路街道","德胜街道"],"朝阳区":["朝外街道","劲松街道","呼家楼街道","三里屯街道","团结湖街道"],"海淀区":["海淀街道","中关村街道","学院路街道","西三旗街道","清河街道"]},"上海市":{"黄浦区":["南京东路街道","外滩街道","瑞金二路街道","淮海中路街道","豫园街道"],"徐汇区":["天平路街道","湖南路街道","斜土路街道","枫林路街道","长桥街道"],"浦东新区":["陆家嘴街道","潍坊新村街道","塘桥街道","南码头路街道","周家渡街道"]},"广州市":{"天河区":["五山街道","员村街道","车陂街道","沙河街道","石牌街道"],"海珠区":["赤岗街道","新港街道","昌岗街道","江南中街道","滨江街道"],"越秀区":["洪桥街道","北京街道","六榕街道","流花街道","光塔街道"]}}[e])?void 0:r[t])||[]}})},addRegion(e,t,r){return l(this,null,function*(){try{return(yield O("/regions",{method:"POST",data:{city:e,district:t,community:r}})).success}catch(n){return!0}})}};export{v as a,O as b,T as o,S as p,_ as r,P as u};
|