TransactionCharts.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="charts-card uni-row2">
  3. <view class="charts-header">
  4. <view class="charts-title">{{typeMap.find(item => item.value === search.type)?.text}}</view>
  5. <uni-datetime-picker type="daterange" v-model="search.date"
  6. :placeholder="t('placeholder.Start') + ' - ' + t('placeholder.End')" @change="handleDateChange" />
  7. </view>
  8. <view class="charts-account" v-if="search.login">
  9. <text v-t="'Label.TradingAccount'"></text>
  10. <text> - </text>
  11. <text>{{ search.login }}</text>
  12. </view>
  13. <view class="search-bar">
  14. <cwg-combox v-model:value="search.type" :clearable="false" :options="typeMap"
  15. :placeholder="t('Label.ChartType')" />
  16. <cwg-combox v-model:value="search.platform" :clearable="false" :options="platformMap"
  17. :placeholder="t('Label.PlatformType')" />
  18. <cwg-combox v-model:value="search.login" :clearable="false" :options="loginOptions"
  19. :placeholder="t('Label.TradingAccount')" />
  20. <view class="s-btn" @click="getChart" v-t="'Btn.Confirm'" />
  21. </view>
  22. <view class="charts-box">
  23. <cwg-charts type="column" :chartData="chartsDataColumn1" :echartsH5="true" :echartsApp="true"
  24. @complete="complete" />
  25. </view>
  26. </view>
  27. </template>
  28. <script setup lang="ts">
  29. import { computed, ref, onMounted, watch } from 'vue';
  30. import { useI18n } from 'vue-i18n';
  31. const { t, locale } = useI18n();
  32. import { customApi } from '@/service/custom';
  33. import useUserStore from "@/stores/use-user-store";
  34. import useRouter from "@/hooks/useRouter";
  35. import { start } from 'repl';
  36. const router = useRouter();
  37. const search = ref({
  38. type: 4,
  39. platform: 'MT4',
  40. login: null,
  41. date: [],
  42. startDate: null,
  43. endDate: null
  44. })
  45. const typeMap = computed(() => ([
  46. { value: 4, text: t('Custom.Index.TradingVolumeStatistics') },
  47. { value: 2, text: t('Custom.Index.DepositStatistical') },
  48. { value: 3, text: t('Custom.Index.WithdrawalsStatistical') },
  49. { value: 6, text: t('Custom.Index.ProfitLoss') },
  50. ]));
  51. const platformMap = computed(() => ([
  52. { value: 'MT4', text: 'MT4' },
  53. { value: 'MT5', text: 'MT5' }
  54. ]));
  55. const loginOptions = ref([])
  56. const getAccountList = async () => {
  57. let res = await customApi.CustomDropdown({
  58. platform: search.value.platform
  59. });
  60. if (res.code == 200) {
  61. loginOptions.value = res.data.map(item => ({
  62. value: item.login,
  63. text: item.login
  64. }))
  65. } else {
  66. loginOptions.value = []
  67. }
  68. }
  69. const flag = ref(false) // 防止重复请求
  70. const handleDateChange = (val) => {
  71. search.value.startDate = val[0]
  72. search.value.endDate = val[1]
  73. getChart()
  74. }
  75. //获取图表信息
  76. const getChart = async () => {
  77. if (flag.value) {
  78. return;
  79. } else {
  80. flag.value = true;
  81. }
  82. // chartDates.value = [];
  83. // chartTimes.value = [];
  84. let res = await customApi.getChartInfo({
  85. ...search.value,
  86. });
  87. if (res.code == 200) {
  88. // res.data.forEach((item) => {
  89. // chartDates.value.push(item.amount);
  90. // chartTimes.value.push(item.date.split(" ")[0]);
  91. // });
  92. // drawLine();
  93. // $pigeon.MessageOK($i18n.t("Msg.SearchSuccess"));
  94. flag.value = false;
  95. } else {
  96. flag.value = false;
  97. }
  98. }
  99. const chartsDataColumn1 = ref({
  100. categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  101. series: [
  102. {
  103. name: 'Promotion A',
  104. data: [29, 71, 106, 129, 144, 176, 135, 148, 216, 194, 95, 54]
  105. },
  106. {
  107. name: 'Promotion B',
  108. data: [39, 81, 116, 139, 154, 186, 145, 158, 226, 204, 105, 64]
  109. }
  110. ]
  111. })
  112. const complete = (e) => {
  113. console.log("渲染完成事件", e);
  114. }
  115. const time = ref('')
  116. const getDate = () => {
  117. let timezone = 2; //目标时区时间,东2区 东时区正数 西市区负数
  118. let offset_GMT = new Date().getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟
  119. let nowDate = new Date().getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数
  120. let now = new Date(
  121. nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000
  122. );
  123. //当前时间
  124. let month = now.getMonth() + 1; //月
  125. let day = now.getDate(); //日
  126. let hh = now.getHours(); //时
  127. let mm = now.getMinutes(); //分
  128. let clock;
  129. if (month < 10) {
  130. month = "0" + month;
  131. }
  132. if (day < 10) {
  133. day = "0" + day;
  134. }
  135. if (hh < 10) {
  136. hh = "0" + hh;
  137. }
  138. if (mm < 10) {
  139. mm = "0" + mm;
  140. }
  141. clock = " " + hh + ":" + mm + " " + month + "/" + day;
  142. time.value = clock;
  143. }
  144. // 设置默认日期
  145. const setDefaultDate = () => {
  146. // 先置空
  147. search.value.date = []
  148. // 使用 setTimeout 确保在下一个事件循环赋值
  149. setTimeout(() => {
  150. search.value.date = [search.value.startDate, search.value.endDate];
  151. }, 0)
  152. }
  153. const goTime = () => {
  154. getDate();
  155. let timezone = 2; //目标时区时间,东2区 东时区正数 西市区负数
  156. let offset_GMT = new Date().getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟
  157. let nowDate = new Date().getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数
  158. let data = new Date(
  159. nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000
  160. );
  161. //当月第一天和最后一天
  162. let mon1 = data.setDate(1); //当月第一天
  163. let mon2 = data.setMonth(data.getMonth() + 1); //下月
  164. let y1 = new Date(mon1).getFullYear();
  165. let m1 = new Date(mon1).getMonth() + 1;
  166. let d1 = new Date(mon1).getDate();
  167. let y2 = new Date(mon2).getFullYear();
  168. let m2 = new Date(mon2).getMonth() + 1;
  169. let d2 = 1;
  170. search.value.startDate =
  171. y1 + "-" + (m1 < 10 ? "0" + m1 : m1) + "-" + (d1 < 10 ? "0" + d1 : d1);
  172. search.value.endDate =
  173. y2 + "-" + (m2 < 10 ? "0" + m2 : m2) + "-" + (d2 < 10 ? "0" + d2 : d2);
  174. setDefaultDate();
  175. console.log(search.value.date);
  176. getChart();
  177. }
  178. watch(() => search.value.platform, () => {
  179. loginOptions.value = []
  180. search.value.login = null
  181. getAccountList()
  182. })
  183. onMounted(() => {
  184. getAccountList()
  185. goTime()
  186. })
  187. </script>
  188. <style scoped lang="scss">
  189. @import "@/uni.scss";
  190. .charts-card {
  191. width: 100%;
  192. padding: px2rpx(12);
  193. display: flex;
  194. flex-direction: column;
  195. box-sizing: border-box;
  196. background-color: var(--color-white);
  197. .charts-header {
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. height: px2rpx(38);
  202. .uni-date {
  203. width: px2rpx(264) !important;
  204. flex: none;
  205. }
  206. }
  207. .charts-title {
  208. font-size: px2rpx(21);
  209. font-weight: 500;
  210. color: var(--color-slate-800);
  211. }
  212. .charts-account {
  213. margin-top: px2rpx(16);
  214. font-size: px2rpx(16);
  215. font-weight: 700;
  216. color: var(--color-error);
  217. }
  218. .charts-box {
  219. width: 100%;
  220. height: px2rpx(300);
  221. }
  222. }
  223. </style>