websocket.js 759 B

123456789101112131415161718192021222324252627
  1. import store from '@/store'
  2. import config from '@/config'
  3. import { getToken } from '@/utils/auth'
  4. import errorCode from '@/utils/errorCode'
  5. import { toast, showConfirm, tansParams } from '@/utils/common'
  6. const baseUrl = config.socketUrl
  7. const websocket = config => {
  8. // 是否需要设置 token
  9. const isToken = (config.headers || {}).isToken === false
  10. config.header = config.header || {}
  11. let token = "";
  12. if (getToken() && !isToken) {
  13. token = getToken()
  14. }
  15. let SocketTask = uni.connectSocket({
  16. url: config.baseUrl || baseUrl + config.url+""+token,
  17. success:function(res){
  18. },
  19. fail:function (res){
  20. }
  21. })
  22. return SocketTask;
  23. }
  24. export default websocket