index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import axios from 'axios';
  2. import Vue from 'vue';
  3. import context from '../main';
  4. // let loading;
  5. // axios.defaults.timeout = 3000000;
  6. // let loadinginstace;
  7. // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  8. axios.interceptors.request.use(
  9. config => {
  10. config.headers = {
  11. // "Content-Type": "application/json"
  12. // "Content-Type": "text/html"
  13. // "Content-Type":"multipart/form-data"
  14. }
  15. return config;
  16. }, error => {
  17. console.log('error', error);
  18. // loading.close();
  19. if (error) {
  20. context.$alert('网络错误,请稍后再试!','提示',{
  21. confirmButtonText: '确定'
  22. });
  23. return Promise.reject(error);
  24. }
  25. }
  26. );
  27. axios.interceptors.response.use(
  28. res => {
  29. // console.log('响应res', res);
  30. // loading.close();
  31. if (res && res.data && res.data.code == 200) {
  32. return res.data;
  33. }
  34. else {
  35. if (res && res.data) {
  36. if (res.data.message) {
  37. context.$message({
  38. message: res.data.message,
  39. type: 'warning'
  40. });
  41. }
  42. if (res && res.data.code == 10014) {
  43. setTimeout(() => {
  44. context.$router.replace('/login')
  45. }, 2000)
  46. }
  47. }
  48. }
  49. },
  50. err => {
  51. // console.log('err', err);
  52. // loading.close();
  53. // if (err.message.includes('timeout')) {
  54. // err.message = '请求超时';
  55. // context.$router.replace({path:'/login'});
  56. // }
  57. // else
  58. // {
  59. // if (err && err.response) {
  60. // switch (err.response.status) {
  61. // case 400: err.message = '请求错误(400)'; break;
  62. // case 401: err.message = '未授权,请重新登录(401)'; break;
  63. // case 403: err.message = '拒绝访问(403)'; break;
  64. // case 404: err.message = '请求出错(404)'; break;
  65. // case 408: err.message = '请求超时(408)'; break;
  66. // case 500: err.message = '服务器错误(500)'; break;
  67. // case 501: err.message = '服务未实现(501)'; break;
  68. // case 502: err.message = '网络错误(502)'; break;
  69. // case 503: err.message = '服务不可用(503)'; break;
  70. // case 504: err.message = '网络超时(504)'; break;
  71. // case 505: err.message = 'HTTP版本不受支持(505)'; break;
  72. // default: err.message = `连接出错(${err.response.status})!`;
  73. // }
  74. // context.$router.replace({path:'/login'});
  75. // } else {
  76. // err.message = '连接服务器失败!'
  77. // context.$router.replace({path:'/login'});
  78. // }
  79. // }
  80. // context.$alert(err.message,'提示',{
  81. // confirmButtonText: '确定'
  82. // });
  83. return Promise.reject(err);
  84. });
  85. Vue.prototype.$axios = axios;
  86. axios.defaults.headers.get['Pragma'] = 'no-cache';
  87. axios.defaults.headers.get['Cache-Control'] = 'no-cache, no-store';
  88. let requestLoading = (url, method, params) => {
  89. return axios({
  90. method: method,
  91. url: url,
  92. params,
  93. withCredentials: true,
  94. data: params,
  95. timeout: 120000,
  96. })
  97. };
  98. // const Prefix = 'http://192.168.1.220/mchsrv/index.php?';
  99. // const Prefix = 'http://dd.guozipay.com/mchsrv/index.php?';
  100. // const Prefix = 'http://192.168.1.218/mchsrv/index.php?';
  101. const Prefix = `${process.env.VUE_APP_HOST}/mchsrv/index.php?`;
  102. // const Prefix = 'https://test.xyzshops.cn/mchsrv/index.php?';
  103. // 椰子临时线上地址
  104. // const Prefix = 'http://121.89.196.45/mobile/index.php?';
  105. //椰林接口地址
  106. // const Prefix = 'https://ylweb.xyzshops.cn/mchsrv/index.php?';
  107. //测试请求
  108. export const testRequest = () => {
  109. // return requestLoading(`${Prefix}/index.php?index/index/index`, 'get', {})
  110. }
  111. //登录
  112. export const login = (params) => {
  113. console.log(`${Prefix}act=merchant_login&op=login`)
  114. // return requestLoading(`${Prefix}act=merchant_login&op=login&client_type=ajax`, 'post', params)
  115. return axios({
  116. method: 'post',
  117. url: `${Prefix}act=merchant_login&op=login&client_type=ajax`,
  118. withCredentials: true,
  119. headers: {
  120. "Content-Type": "application/x-www-form-urlencoded"
  121. },
  122. data: params,
  123. timeout: 120000,
  124. })
  125. }
  126. //登出
  127. export const loginOut = () => {
  128. return requestLoading(`${Prefix}act=merchant_login&op=logout&client_type=ajax`, 'post')
  129. }
  130. // 获取ip列表
  131. export const getIpList = () => {
  132. return requestLoading(`${Prefix}act=merchant_info&op=ipwhitelist&client_type=ajax`, 'post')
  133. }
  134. // 删除ip列表
  135. export const delIpList = (params) => {
  136. // return requestLoading(`${Prefix}act=merchant_info&op=ipdel&client_type=ajax`, 'post', params)
  137. return axios({
  138. method: 'post',
  139. url: `${Prefix}act=merchant_info&op=ipdel&client_type=ajax`,
  140. withCredentials: true,
  141. headers: {
  142. "Content-Type": "application/x-www-form-urlencoded"
  143. },
  144. data: params,
  145. timeout: 120000,
  146. })
  147. }
  148. // 添加ip
  149. export const addIp = (params) => {
  150. // return requestLoading(`${Prefix}act=merchant_info&op=addip&client_type=ajax&ip=${ip}`, 'post')
  151. return axios({
  152. method: 'post',
  153. url: `${Prefix}act=merchant_info&op=addip&client_type=ajax`,
  154. withCredentials: true,
  155. headers: {
  156. "Content-Type": "application/x-www-form-urlencoded"
  157. },
  158. data: params,
  159. timeout: 120000,
  160. })
  161. }
  162. // 获取订单统计列表
  163. export const getOrderList = (params) => {
  164. // return requestLoading(`${Prefix}act=merchant_order&op=list&client_type=ajax&curpage=${page}`, 'post')
  165. return axios({
  166. method: 'post',
  167. url: `${Prefix}act=merchant_order&op=list&client_type=ajax`,
  168. withCredentials: true,
  169. headers: {
  170. "Content-Type": "application/x-www-form-urlencoded"
  171. },
  172. data: params,
  173. timeout: 120000,
  174. })
  175. }
  176. /**
  177. * 查询订单统计列表
  178. * @param {*} page 页码
  179. * @param {*} start_time 开始时间
  180. * @param {*} end_time 结束时间
  181. * @param {*} card_type 充值类型
  182. */
  183. // export const queryList = (page, start_time, end_time, card_type) => {
  184. export const queryList = (params) => {
  185. // return requestLoading(`${Prefix}act=merchant_order&op=list&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}&card_type=${card_type}`, 'post')
  186. return axios({
  187. method: 'post',
  188. url: `${Prefix}act=merchant_order&op=list&client_type=ajax&page=200`,
  189. withCredentials: true,
  190. headers: {
  191. "Content-Type": "application/x-www-form-urlencoded"
  192. },
  193. data: params,
  194. timeout: 120000,
  195. })
  196. }
  197. // 导出
  198. export const exportList = (params) => {
  199. return axios({
  200. method: 'post',
  201. url: `${Prefix}act=merchant_order&op=OrderExport&client_type=ajax&page=50`,
  202. withCredentials: true,
  203. headers: {
  204. "Content-Type": "application/x-www-form-urlencoded"
  205. },
  206. data: params,
  207. timeout: 120000,
  208. })
  209. }
  210. // 修改管理员密码
  211. export const editPwd = (params) => {
  212. // return requestLoading(`${Prefix}act=merchant_info&op=modifypw&client_type=ajax`, 'post', params)
  213. return axios({
  214. method: 'post',
  215. url: `${Prefix}act=merchant_info&op=modifypw&client_type=ajax`,
  216. withCredentials: true,
  217. headers: {
  218. "Content-Type": "application/x-www-form-urlencoded"
  219. },
  220. data: params,
  221. timeout: 120000,
  222. })
  223. }
  224. // 个人中心
  225. export const getUserInfo = () => {
  226. return requestLoading(`${Prefix}act=merchant_info&op=index&client_type=ajax`, 'post')
  227. }
  228. // 实时动账
  229. export const getMovingAccount = (page) => {
  230. return requestLoading(`${Prefix}act=merchant_info&op=pdlog&client_type=ajax&page=50&curpage=${page}`, 'post')
  231. }
  232. /**
  233. * 查询实时动账
  234. * @param {*} start_time 开始时间
  235. * @param {*} end_time 结束时间
  236. * @param {*} lg_type 变更类型
  237. * @param {*} lg_order_sn 业务单号
  238. */
  239. // export const queryMovingAccount = (page, start_time, end_time, lg_type) => {
  240. export const queryMovingAccount = (params) => {
  241. // return requestLoading(`${Prefix}act=merchant_info&op=pdlog&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}&lg_type=${lg_type}`, 'post')
  242. return axios({
  243. method: 'post',
  244. url: `${Prefix}act=merchant_info&op=pdlog&client_type=ajax&page=50`,
  245. withCredentials: true,
  246. headers: {
  247. "Content-Type": "application/x-www-form-urlencoded"
  248. },
  249. data: params,
  250. timeout: 120000,
  251. })
  252. }
  253. // 导出日志
  254. export const exportMovingAccount = (params) => {
  255. return axios({
  256. method: 'post',
  257. url: `${Prefix}act=merchant_info&op=pdlogexport&client_type=ajax&page=50`,
  258. withCredentials: true,
  259. headers: {
  260. "Content-Type": "application/x-www-form-urlencoded"
  261. },
  262. data: params,
  263. timeout: 120000,
  264. })
  265. }
  266. // 设置密钥
  267. // export const updateKey = (secure_key) => {
  268. export const updateKey = (params) => {
  269. // return requestLoading(`${Prefix}act=merchant_info&op=setkey&client_type=ajax&secure_key=${secure_key}`, 'post')
  270. return axios({
  271. method: 'post',
  272. url: `${Prefix}act=merchant_info&op=setkey&client_type=ajax`,
  273. withCredentials: true,
  274. headers: {
  275. "Content-Type": "application/x-www-form-urlencoded"
  276. },
  277. data: params,
  278. timeout: 120000,
  279. })
  280. }
  281. // 用户设置-提交 充值管理-设置余额预警
  282. export const onSubUser = (params) => {
  283. return axios({
  284. method: 'post',
  285. url: `${Prefix}act=merchant_info&op=setcontact&client_type=ajax`,
  286. withCredentials: true,
  287. headers: {
  288. "Content-Type": "application/x-www-form-urlencoded"
  289. },
  290. data: params,
  291. timeout: 120000,
  292. })
  293. }
  294. // 上传文件
  295. export const updateVoucher = (name) => {
  296. // return requestLoading(`${Prefix}act=merchant_recharge&op=voucherupload&client_type=ajax`, 'post', {voucher})
  297. return axios({
  298. method: "post",
  299. // url: `http://192.168.1.218/upfile.php`,
  300. // url: `http://dd.guozipay.com/upfile.php`,
  301. // url: `https://www.xyzshops.cn/upfile.php`,
  302. url: `${process.env.VUE_APP_HOST}/upfile.php`,
  303. //椰林接口地址
  304. // url : 'https://ylweb.xyzshops.cn/upfile.php',
  305. // url: `https://test.xyzshops.cn/upfile.php`,
  306. // 椰子临时
  307. // url: `http://121.89.196.45/upfile.php`,
  308. // withCredentials: true,
  309. data: name,
  310. timeout: 120000,
  311. })
  312. }
  313. // 上传凭证
  314. export const updateVoucherList = (params) => {
  315. // return requestLoading(`${Prefix}act=refill_evidence&op=add&client_type=ajax`, 'post', params)
  316. return axios({
  317. method: 'post',
  318. url: `${Prefix}act=refill_evidence&op=add&client_type=ajax`,
  319. withCredentials: true,
  320. headers: {
  321. "Content-Type": "application/x-www-form-urlencoded"
  322. },
  323. data: params,
  324. timeout: 120000,
  325. })
  326. }
  327. // 获取充值列表
  328. export const getVoucherList = () => {
  329. return requestLoading(`${Prefix}act=refill_evidence&op=index&client_type=ajax&page=50`, 'post')
  330. }
  331. // 查询充值列表
  332. // export const queryVoucherList = (page, start_time, end_time) => {
  333. export const queryVoucherList = (params) => {
  334. // return requestLoading(`${Prefix}act=refill_evidence&op=index&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}`, 'get')
  335. return axios({
  336. method: 'post',
  337. url: `${Prefix}act=refill_evidence&op=index&client_type=ajax&page=50`,
  338. withCredentials: true,
  339. headers: {
  340. "Content-Type": "application/x-www-form-urlencoded"
  341. },
  342. data: params,
  343. timeout: 120000,
  344. })
  345. }
  346. // 获取充值金额
  347. export const getRechargeAmount = () => {
  348. return requestLoading(`${Prefix}act=merchant_refill&op=goods&client_type=ajax`, 'post')
  349. }
  350. // 油卡充值 cardno-卡号 amount-充值金额
  351. export const OilCardRecharge = (params) => {
  352. // return requestLoading(`${Prefix}act=merchant_refill&op=add&client_type=ajax`, 'post', params)
  353. return axios({
  354. method: 'post',
  355. url: `${Prefix}act=merchant_refill&op=add&client_type=ajax`,
  356. withCredentials: true,
  357. headers: {
  358. "Content-Type": "application/x-www-form-urlencoded"
  359. },
  360. data: params,
  361. timeout: 120000,
  362. })
  363. }
  364. // 首页
  365. export const getHomeData = () => {
  366. return requestLoading(`${Prefix}act=merchant_info&op=home&client_type=ajax`, 'post')
  367. }
  368. // 添加余额预警电话
  369. export const addwphone = (params) => {
  370. return axios({
  371. method: 'post',
  372. url: `${Prefix}act=merchant_info&op=addwphone&client_type=ajax`,
  373. withCredentials: true,
  374. headers: {
  375. "Content-Type": "application/x-www-form-urlencoded"
  376. },
  377. data: params,
  378. timeout: 120000,
  379. })
  380. }
  381. // 删除余额预警电话
  382. export const delwphone = (params) => {
  383. return axios({
  384. method: 'post',
  385. url: `${Prefix}act=merchant_info&op=wphonedel&client_type=ajax`,
  386. withCredentials: true,
  387. headers: {
  388. "Content-Type": "application/x-www-form-urlencoded"
  389. },
  390. data: params,
  391. timeout: 120000,
  392. })
  393. }
  394. // 对账管理
  395. export const getRec = (params) => {
  396. return axios({
  397. method: 'post',
  398. url: `${Prefix}act=merchant_order&op=OrderStats&client_type=ajax`,
  399. withCredentials: true,
  400. headers: {
  401. "Content-Type": "application/x-www-form-urlencoded"
  402. },
  403. data: params,
  404. timeout: 120000,
  405. })
  406. }
  407. // 对账管理导出订单
  408. export const getExportOrder = (params) => {
  409. return axios({
  410. method: 'post',
  411. url: `${Prefix}act=merchant_order&op=create_task&client_type=ajax`,
  412. withCredentials: true,
  413. headers: {
  414. "Content-Type": "application/x-www-form-urlencoded"
  415. },
  416. data: params,
  417. timeout: 120000,
  418. })
  419. }
  420. // 对账管理获取导出订单列表
  421. export const getExportOrderList = (curpage) => {
  422. return axios({
  423. method: 'post',
  424. url: `${Prefix}act=merchant_order&op=task_list&client_type=ajax&curpage=${curpage}`,
  425. withCredentials: true,
  426. headers: {
  427. "Content-Type": "application/x-www-form-urlencoded"
  428. },
  429. data: {},
  430. timeout: 120000,
  431. })
  432. }
  433. // 设置话费充值
  434. export const phonrRec = (params) => {
  435. return axios({
  436. method: 'post',
  437. url: `${Prefix}act=merchant_info&op=SetQualityTimeOut&client_type=ajax`,
  438. withCredentials: true,
  439. headers: {
  440. "Content-Type": "application/x-www-form-urlencoded"
  441. },
  442. data: params,
  443. timeout: 120000,
  444. })
  445. }