index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // @ts-ignore
  2. import Cookie from 'js-cookie';
  3. export const appVersionCode = 12;
  4. export const appType = 1;
  5. // 获取host
  6. export const getEnvConfig = () => {
  7. let host
  8. // @ts-ignore
  9. switch(process.env.NODE_ENV) {
  10. case `production`:
  11. host = `https://api.denetme.net`
  12. break;
  13. case `pre`:
  14. host = `https://preapi.denetme.net`
  15. break;
  16. default:
  17. host = `https://testapi.denetme.net`
  18. break;
  19. }
  20. return {
  21. host
  22. };
  23. }
  24. // 获取mid
  25. export const getMid = () => {
  26. let _mid;
  27. let _cookie_mid_arr = Cookie.get('mid') || []
  28. if (_cookie_mid_arr.length > 0) {
  29. _mid = JSON.parse(_cookie_mid_arr)[0].mid
  30. } else {
  31. _mid = guid()
  32. Cookie.set('mid', JSON.stringify([{ mid: _mid }]), { expires: 1000 })
  33. }
  34. return _mid;
  35. }
  36. // 推特授权url
  37. export const getOauthUrl = (token: string) => {
  38. return `https://api.twitter.com/oauth/authenticate?oauth_token=${token}`
  39. }
  40. // 创建窗口
  41. export const createWindow = (url: string, w: number = 400, h: number = 600) => {
  42. var left = Math.round((window.screen.availWidth - w) / 2);
  43. var top = Math.round((window.screen.availHeight - 100 - h) / 2);
  44. var win = window.open(url, `newWin`, `width=${w}, height=${h}, top=${top}, left=${left}, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no`);
  45. return win;
  46. }
  47. // 帮助函数
  48. const guid = () => {
  49. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  50. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  51. return v.toString(16);
  52. });
  53. }
  54. // 获取cookie
  55. export const getCookie = (name: string) => {
  56. if (name) {
  57. let getVal = Cookie.get(name)
  58. return getVal
  59. }
  60. }
  61. // 设置cookie
  62. export const setCookie = (name: string, val: any) => {
  63. Cookie.set(name, JSON.stringify(val), { expires: 1000 })
  64. }