瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

393 lines
7.1 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
  1. import http from './http.js'
  2. import utils from '../utils/utils.js'
  3. let limit = {}
  4. let debounce = {}
  5. const config = {
  6. // 示例
  7. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  8. // auth : false, showLoading : true, loadingTitle : '加载中...',
  9. // limit : 1000
  10. // },
  11. getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
  12. // 微信登录接口
  13. wxLogin: {
  14. url: '/login/login',
  15. method: 'GET',
  16. limit : 500,
  17. showLoading : true,
  18. },
  19. // 修改个人信息接口
  20. updateInfo: {
  21. url: '/token/updateInfo',
  22. method: 'POST',
  23. auth: true,
  24. limit : 500,
  25. showLoading : true,
  26. },
  27. // 获取个人信息接口
  28. getInfo: {
  29. url: '/token/getInfo',
  30. method: 'GET',
  31. auth: true,
  32. limit : 500,
  33. },
  34. //隐私政策
  35. getPrivacyPolicy: {
  36. url: '/login/getPrivacyPolicy',
  37. method: 'GET',
  38. },
  39. //用户协议
  40. getUserAgreement: {
  41. url: '/login/getUserAgreement',
  42. method: 'GET',
  43. },
  44. // 不需要登录的接口
  45. //获取分类
  46. getClassInfo: {
  47. url: '/city/getClassInfo',
  48. method: 'GET',
  49. },
  50. //获取首页头部信息
  51. getIndexHeaderInfo: {
  52. url: '/city/getIndexHeaderInfo',
  53. method: 'GET',
  54. },
  55. //获取banner列表
  56. getBannerList: {
  57. url: '/city/getBannerList',
  58. method: 'GET',
  59. },
  60. //获取分类类型列表
  61. getClassifyList: {
  62. url: '/city/getClassifyList',
  63. method: 'GET',
  64. },
  65. //获取工作信息列表
  66. getJobPage: {
  67. url: '/city/getJobPage',
  68. method: 'GET',
  69. },
  70. //获取工作详情
  71. getJobDetail: {
  72. url: '/city/getJobDetail',
  73. method: 'GET',
  74. },
  75. //根据分类获取租房信息列表
  76. getRentPage: {
  77. url: '/city/getRentPage',
  78. method: 'GET',
  79. },
  80. //获取租房详情
  81. getRentDetail: {
  82. url: '/city/getRentDetail',
  83. method: 'GET',
  84. },
  85. //获取动态帖子列表
  86. getPostPage: {
  87. url: '/city/getPostPage',
  88. method: 'GET',
  89. },
  90. //获取帖子详情
  91. getPostDetail: {
  92. url: '/city/getPostDetail',
  93. method: 'GET',
  94. },
  95. //获取活动列表信息
  96. getActivityPage: {
  97. url: '/city/getActivityPage',
  98. method: 'GET',
  99. },
  100. //获取活动详情
  101. getActivityDetail: {
  102. url: '/city/getActivityDetail',
  103. method: 'GET',
  104. },
  105. //获取活动详情
  106. getActivityDetail: {
  107. url: '/city/getActivityDetail',
  108. method: 'GET',
  109. },
  110. //获取门店信息列表(美食)
  111. getStorePage: {
  112. url: '/city/getStorePage',
  113. method: 'GET',
  114. },
  115. //获取门店详情(美食)
  116. getStoreDetail: {
  117. url: '/city/getStoreDetail',
  118. method: 'GET',
  119. },
  120. //发布按钮列表
  121. getPublishList: {
  122. url: '/city/getPublishList',
  123. method: 'GET',
  124. },
  125. //获取城市列表服务区域
  126. getCityList: {
  127. url: '/city/getCityList',
  128. method: 'GET',
  129. },
  130. //获取景点列表带分页
  131. getScenicPage: {
  132. url: '/city/getScenicPage',
  133. method: 'GET',
  134. },
  135. //获取景点详情
  136. getScenicDetail: {
  137. url: '/city/getScenicDetail',
  138. method: 'GET',
  139. },
  140. //获取评论列表type-0帖子-1租房-2工作-3景点-4美食-5活动-6人找车-7车找人
  141. getCommentPage: {
  142. url: '/city/getCommentPage',
  143. method: 'GET',
  144. },
  145. //获取江华人信息接口
  146. getJiangHuInfo: {
  147. url: '/city/getJiangHuInfo',
  148. method: 'GET',
  149. },
  150. //获取人找车分页列表
  151. getPeoplePage: {
  152. url: '/city/getPeoplePage',
  153. method: 'GET',
  154. },
  155. //获取人找车详情
  156. getPeopleDetail: {
  157. url: '/city/getPeopleDetail',
  158. method: 'GET',
  159. },
  160. //获取车找人分页列表
  161. getCatPage: {
  162. url: '/city/getCatPage',
  163. method: 'GET',
  164. },
  165. //获取车找人详情
  166. getCatDetail: {
  167. url: '/city/getCatDetail',
  168. method: 'GET',
  169. },
  170. //查询商城信息列表带分页
  171. getShopPingPage : {
  172. url: '/city/getShopPingPage',
  173. method: 'GET',
  174. },
  175. //根据商品标识查询商品信息详情
  176. getShopPingDetail : {
  177. url: '/city/getShopPingDetail',
  178. method: 'GET',
  179. },
  180. //发布帖子\动态
  181. publishPost: {
  182. url: '/token/publishPost',
  183. method: 'POST',
  184. limit : 1000,
  185. auth : true,
  186. showLoading : true,
  187. },
  188. //发布评论
  189. addComment: {
  190. url: '/token/addComment',
  191. method: 'POST',
  192. limit : 1000,
  193. auth : true,
  194. showLoading : true,
  195. },
  196. //发布租房信息
  197. publishRent: {
  198. url: '/token/publishRent',
  199. method: 'POST',
  200. limit : 1000,
  201. auth : true,
  202. showLoading : true,
  203. },
  204. //发布招聘信息
  205. publishJob: {
  206. url: '/token/publishJob',
  207. method: 'POST',
  208. limit : 1000,
  209. auth : true,
  210. showLoading : true,
  211. },
  212. //发布车找人信息
  213. publishCar: {
  214. url: '/token/publishCar',
  215. method: 'POST',
  216. limit : 1000,
  217. auth : true,
  218. showLoading : true,
  219. },
  220. //查询自己发布的动态
  221. getMyPostPage: {
  222. url: '/token/getMyPostPage',
  223. method: 'GET',
  224. auth : true,
  225. },
  226. //删除自己发布的动态
  227. deletePost: {
  228. url: '/token/deletePost',
  229. method: 'POST',
  230. auth : true,
  231. showLoading : true,
  232. },
  233. //店铺认证
  234. companyAuthentication: {
  235. url: '/token/companyAuthentication',
  236. method: 'POST',
  237. limit : 1000,
  238. auth : true,
  239. showLoading : true,
  240. },
  241. //个人认证
  242. personalAuthentication: {
  243. url: '/token/personalAuthentication',
  244. method: 'POST',
  245. limit : 1000,
  246. auth : true,
  247. showLoading : true,
  248. },
  249. //获取分享二维码
  250. getQrCode: {
  251. url: '/token/getQrCode',
  252. method: 'GET',
  253. auth : true,
  254. },
  255. //获取粉丝列表接口
  256. getFansList: {
  257. url: '/token/getFansList',
  258. method: 'GET',
  259. auth : true,
  260. },
  261. // 用户查询地址列表
  262. getAddressList : {
  263. url: '/token/getAddressList',
  264. method: 'GET',
  265. auth : true,
  266. },
  267. // 用户获取地址信息列表详情
  268. getAddressDetail : {
  269. url: '/token/getAddressDetail',
  270. method: 'GET',
  271. auth : true,
  272. },
  273. // 用户增加或者编辑地址信息
  274. addOrEditAddress : {
  275. url: '/token/addOrEditAddress',
  276. method: 'POST',
  277. auth : true,
  278. showLoading : true,
  279. limit : 1000,
  280. },
  281. // 删除地址
  282. deleteAddress : {
  283. url: '/token/deleteAddress',
  284. method: 'POST',
  285. auth : true,
  286. showLoading : true,
  287. },
  288. }
  289. const models = ['order']
  290. models.forEach(key => {
  291. addApiModel(require(`./model/${key}.js`).default, key)
  292. })
  293. export function api(key, data, callback, loadingTitle) {
  294. let req = config[key]
  295. if (!req) {
  296. console.error('无效key--------' + key);
  297. return
  298. }
  299. if (typeof callback == 'string') {
  300. loadingTitle = callback
  301. }
  302. if (typeof data == 'function') {
  303. callback = data
  304. data = {}
  305. }
  306. // 接口限流
  307. if (req.limit) {
  308. let storageKey = req.url
  309. let storage = limit[storageKey]
  310. if (storage && new Date().getTime() - storage < req.limit) {
  311. return
  312. }
  313. limit[storageKey] = new Date().getTime()
  314. }
  315. //必须登录
  316. if (req.auth) {
  317. if (!uni.getStorageSync('token')) {
  318. utils.toLogin()
  319. console.error('需要登录')
  320. return
  321. }
  322. }
  323. // 接口防抖
  324. if(req.debounce){
  325. let storageKey = req.url
  326. let storage = debounce[storageKey]
  327. if (storage) {
  328. clearTimeout(storage)
  329. }
  330. debounce[storageKey] = setTimeout(() => {
  331. clearTimeout(storage)
  332. delete debounce[storageKey]
  333. http.http(req.url, data, callback, req.method,
  334. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  335. }, req.debounce)
  336. return
  337. }
  338. http.http(req.url, data, callback, req.method,
  339. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  340. }
  341. function addApiModel(model, key){
  342. for(let k in model){
  343. if(config[`${k}`]){
  344. console.error(`重名api------model=${key},key=${k}`);
  345. continue
  346. }
  347. config[`${k}`] = model[k]
  348. // config[`${key}_${k}`] = model[k]
  349. }
  350. }
  351. export default api