sdkUtil.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { config } from "../config/config"
  2. import { log } from "./log"
  3. import { tools } from "./tools"
  4. export class sdkUtil {
  5. public static login(cb:Function) {
  6. switch (tools.platform){
  7. case config.Platform.H5:
  8. cb && cb(null)
  9. break
  10. case config.Platform.WEIXIN:
  11. wx.login({
  12. success(res) {
  13. let code = res.code
  14. log.Debug("wx_code",code)
  15. cb && cb({'code':code})
  16. },
  17. fail(e) { log.Debug(`wx_login 调用失败:`,e) }
  18. })
  19. break;
  20. case config.Platform.TOUTIAO:
  21. tt.login({
  22. force: true,
  23. success(res) {
  24. let code = res.code
  25. let anonymousCode = res.anonymousCode
  26. log.Debug("tt_code",code,'tt_anonymousCode',anonymousCode)
  27. cb && cb({'code':code,'anonymousCode':anonymousCode})
  28. },
  29. fail(e) { log.Debug(`tt_login 调用失败:`,e) }
  30. });
  31. break;
  32. default:
  33. break;
  34. }
  35. }
  36. /**
  37. * 添加桌面
  38. */
  39. public static addShortcut(cb:Function) {
  40. switch (tools.platform){
  41. case config.Platform.WEIXIN:
  42. wx.addShortcut({
  43. success() {
  44. console.log("添加桌面成功");
  45. cb && cb()
  46. },
  47. fail(err) {
  48. console.log("添加桌面失败", err.errMsg);
  49. },
  50. });
  51. break;
  52. case config.Platform.TOUTIAO:
  53. tt.addShortcut({
  54. success() {
  55. console.log("添加桌面成功");
  56. cb && cb()
  57. },
  58. fail(err) {
  59. console.log("添加桌面失败", err.errMsg);
  60. },
  61. });
  62. break;
  63. default:
  64. cb && cb()
  65. break;
  66. }
  67. }
  68. }