dcc
2024-06-13 3616db170333df7d668c97323344335b52c4153c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<template>
  <div>
    <common-header v-if="route.meta.commonHeader"></common-header>
    <router-view />
    <!-- 客服 -->
    <div v-if="!show_kefu" class="service-box">
      <img
        src="@/assets/images/exchangeHome/service1.png"
        alt=""
        width="60"
        height="60"
        @click="changeChatShow(true)"
      />
    </div>
    <!-- serviceUrl客服接口返回的地址 如果没有就用Chat组件默认客服 有就使用iframe嵌套serviceUrl地址 -->
    <div v-if="serviceUrl"> 
      <div v-if="show_kefu" class="kefu" style="z-index: 999999">
        <VueDragResize
          :isActive="true"
          :w="500"
          :h="620"
          v-on:resizing="resize"
          class="kefu-tuozhuai"
          @click="activateEv"
          :isResizable="false"
          v-on:dragging="resize"
        >
          <div class="kefu-title">
            <span>{{ $t("message.home.home43") }}</span>
            <img
              src="@/assets/images/exchangeHome/Group609.png"
              @click="() => changeChatShow(false)"
            />
          </div>
          <iframe :src="serviceUrl" width="500" height="600" frameborder="0"></iframe>
        </VueDragResize>
      </div>
    </div>
    <div v-else>
      <div v-if="show_kefu" class="kefu" style="z-index: 999999">
        <VueDragResize
          :isActive="true"
          :w="432"
          :h="620"
          v-on:resizing="resize"
          class="kefu-tuozhuai"
          @click="activateEv"
          :isResizable="false"
          v-on:dragging="resize"
        >
          <div class="kefu-title">
            <span>{{ $t("message.home.home43") }}</span>
            <img
              src="@/assets/images/exchangeHome/Group609.png"
              @click="() => changeChatShow(false)"
            />
          </div>
          <iframe src="" frameborder="0"></iframe>
          <div class="kegu-nrkegu-nr">
            <Chat ref="chatRef" />
          </div>
        </VueDragResize>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { onMounted } from "vue";
import { useUserStore } from "@/store/user";
import { useRoute,useRouter } from "vue-router";
import VueDragResize from "vue-drag-resize/src"; //https://blog.csdn.net/weixin_50644805/article/details/125980693
import { useLanguageStore, curlang } from "@/store/lang";
import CommonHeader from "@/components/layout/commonHeader.vue"; //非首页的头部
import Chat from "@/components/chat/index.vue";
import { useCurrencyStore } from "@/store/currency.js";
import Axios from "@/api/currency.js";
import axios from "@/api/login.js";
import { setStorage } from "@/utils/index";
// import {getServiceUrl} from './api/login.js';
 
const langStore = useLanguageStore();
const userStore = useUserStore();
const currencyStore = useCurrencyStore();
const route = useRoute();
const router = useRouter();
const show_kefu = ref(false);
const chatUrl = ref("");
const serviceUrl = ref("");
const chatRef = ref();
 
const geturlkey = (name) => {
  return (
    decodeURIComponent(
      (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(location.href) || [
        ,
        "",
      ])[1].replace(/\+/g, "%20")
    ) || null
  );
};
let usercode = geturlkey("usercode");
if (usercode) {
  console.log(userStore.userInfo && userStore.userInfo.token);
  !userStore.userInfo?.token && router.push('/register')
  setStorage("usercode", usercode);
}
onBeforeMount(() => {
  getAllCurrency();
});
 
onMounted(() => {
  langStore.updateLang(curlang);
  const host_url = window.location.hostname;
  axios.getServiceUrl({
    code: "customer_service_url",
  }).then((res) => {
    //第三方客服
    if (res.code == 0 && res.data.customer_service_url != "") {
      serviceUrl.value = res.data.customer_service_url;
    } else {
      //自有客服
      if (userStore.existToken) {
        chatUrl.value =
          "https://" +
          host_url +
          "/chat/#/?token=" +
          userStore.userInfo.token +
          "&lang=" +
          langStore.language;
      } else {
        chatUrl.value =
          "https://" + host_url + "/chat/#/?lang=" + langStore.language;
      }
    }
  });
});
// 获取所有币种,保证头部打开时的默认symbol是存在的
const getAllCurrency = async () => {
  let res = await Axios.getAllSymbolDetails();
  if (res.code == "0") {
    let etfData = [];
    let cryptosData = [];
    let forexData = [];
    let usStackData = [];
    let hkStackData = [];
    let cnStackData = [];
    let twStackData = [];
 
    res.data.forEach((element) => {
      switch (element.type) {
        case "indices":
          if (element.amount) {
            etfData.push(element);
          }
 
          break;
        case "US-stocks":
          usStackData.push(element);
          break;
        case "HK-stocks":
          hkStackData.push(element);
          break;
        case "A-stocks":
          cnStackData.push(element);
          break;
        case "TW-stocks":
          twStackData.push(element);
          break;
 
        case "cryptos":
          cryptosData.push(element);
          break;
        case "forex":
          forexData.push(element);
          break;
        default:
      }
    });
    currencyStore.updateCurrency(etfData, "etf");
    currencyStore.updateCurrency(forexData, "forex");
    currencyStore.updateCurrency(usStackData, "usStocks");
    currencyStore.updateCurrency(hkStackData, "hkStocks");
    currencyStore.updateCurrency(twStackData, "twStocks");
    currencyStore.updateCurrency(cnStackData, "cnStocks");
    currencyStore.updateCurrency(cryptosData, "coin");
  }
};
// 全局的错误
onErrorCaptured((err) => {
  console.log("APP Caught error", err);
  return false;
});
const activateEv = (index) => {
  // 文本框无法输入的问题
  if (chatRef.value && chatRef.value.$refs["input"]) {
    chatRef.value.$refs["input"].focus();
  }
};
 
const changeChatShow = (val) => {
  show_kefu.value = val;
};
 
const kefuBtn = () => {
  console.log("test");
  console.log("test2");
  if (!serviceUrl.value) {
    changeChatShow(true);
  } else {
    window.open(serviceUrl.value);
  }
};
</script>
 
<style>
#app {
  min-height: 100vh;
  overflow-x: hidden;
}
body {
  margin: 0;
}
/* 客服 */
.service-box {
  position: fixed;
  right: 15px;
  bottom: 1px;
  cursor: pointer;
  z-index: 9999;
}
.vdr.active:before {
  display: none;
}
 
.item-dropdown-wrapper.el-dropdown-menu,
.quotes-dropdown.el-dropdown-menu {
  background: #24282d !important;
  border: 1px solid #24282d !important;
}
 
.popper__arrow {
  border-bottom-color: #24282d !important;
}
 
.el-popper[x-placement^="bottom"] .popper__arrow::after {
  border-bottom-color: #24282d !important;
}
 
.item-dropdown-wrapper .el-dropdown-menu__item:focus,
.item-dropdown-wrapper .el-dropdown-menu__item:not(.is-disabled):hover {
  background-color: transparent !important;
  color: #1d91ff !important;
}
 
.quotes-dropdown.el-dropdown-menu {
  padding: 0 !important;
}
 
.quotes-dropdown .el-dropdown-menu__item {
  min-width: 60px !important;
  padding: 6px 13px !important;
}
 
.quotes-dropdown .el-dropdown-menu__item:hover {
  background: #2c3138 !important;
}
</style>
<style scoped>
.kefu {
  position: fixed;
  right: 500px;
  top: 200px;
  cursor: pointer;
  z-index: 3;
}
.embed-responsive-item {
  width: 100%;
  height: 100%;
  border: none;
}
.kefu-title {
  width: 100%;
  height: 61px;
  position: relative;
  text-align: center;
  background: linear-gradient(
    90.3deg,
    rgba(45, 45, 53, 0.71) 0.21%,
    #23232e 99.83%
  );
  border-radius: 10px 10px 0px 0px;
}
.kegu-nrkegu-nr {
  width: 100%;
  height: 559px;
}
.kefu-title span {
  text-align: center;
  font-style: normal;
  font-weight: 400;
  font-size: 20px;
  line-height: 61px;
  color: #ffffff;
}
.kefu-title img {
  position: absolute;
  width: 30px;
  height: 30px;
  right: 21px;
  top: 16px;
}
 
:deep(.kefu-title) .date {
  color: #fff !important;
}
.kefu-tuozhuai {
  box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5);
  outline: none;
  background: #ffffff;
  border-radius: 10px;
}
</style>