index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import Config from '@/config'
  2. import Store from '@/store'
  3. export const webSocket = {
  4. methods: {
  5. connectWebSocket(userId) {
  6. // let webSocket = new WebSocket(`ws://192.168.1.3:8877/api/xiaoshi/ws/` + userId)
  7. let webSocket = new WebSocket(`${this.$c.WebSocketPath}/api/xiaoshi/ws/` + userId)
  8. Store.commit('SET_WEB_SOCKET', webSocket)
  9. webSocket.onopen = () => {
  10. console.log('WebSocket连接成功')
  11. }
  12. webSocket.onmessage = async (e) => {
  13. if (e.data.indexOf('{') == -1) {
  14. return false
  15. }
  16. const { code, data, message } = JSON.parse(e.data)
  17. if (code == 903 || code == 600) {
  18. if (data.complete) {
  19. this.$message.success(`导入完成`)
  20. } else {
  21. }
  22. }
  23. // 603导出专利完成605导出PDF完成
  24. if (code == 603 || code == 605) {
  25. if (data.complete) {
  26. this.$message.success(`导出完成`)
  27. } else {
  28. }
  29. }
  30. }
  31. webSocket.onerror = () => {
  32. console.log('WebSocket连接失败')
  33. }
  34. webSocket.onclose = () => {
  35. console.log('WebSocket连接关闭')
  36. }
  37. }
  38. }
  39. }
  40. export const commonData = {
  41. mounted() {
  42. // this.DictMessage()
  43. // this.getUserInfo()
  44. // this.getScenario()
  45. },
  46. methods: {
  47. //获取个人信息
  48. async getUserInfo() {
  49. // var userinfo = this.$s.getObj('userinfo')
  50. // if(userinfo){
  51. // this.$store.commit('SET_USERINFO', {})
  52. // }
  53. await this.$api.getUserInfo().then(response => {
  54. localStorage.tenant = response.data.tenantId
  55. this.$store.commit('SET_USERINFO', response.data)
  56. })
  57. },
  58. //获取字典项
  59. async DictMessage() {
  60. await this.$api.getOsSystemDict([]).then(response => {
  61. this.$store.commit("SET_DictMessage", response.data)
  62. })
  63. },
  64. //获取应用场景
  65. getScenario() {
  66. this.$api.getScenario().then(response => {
  67. this.$store.commit("SET_Scenario", response.data.data)
  68. })
  69. },
  70. //获取调查类型
  71. getMatter() {
  72. this.$api.getMatter([]).then(response => {
  73. this.$store.commit("SET_Matter", response.data.data)
  74. })
  75. },
  76. //获取权限
  77. async getPermissionList() {
  78. var code = "e424f3cc4f8138f0f68bef092b92212f;6a8d3f4d1d5f11eda41c00163e2f0200"
  79. await this.$api.getPermissionList({ code: code }).then(response => {
  80. this.$store.commit('SET_PERMISSION', response.data)
  81. }).catch(error => {
  82. this.$store.commit('SET_PERMISSION', [])
  83. })
  84. },
  85. }
  86. }