index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="account-status"
  3. @contextmenu.prevent>
  4. <firstMenu :list="menulist"
  5. :value="'value'"
  6. @selectMenu="selectMenu" />
  7. <div class="tip">最新更新时间:{{updatedTime}}</div>
  8. <a-table :columns="columns"
  9. :data-source="list"
  10. :pagination="false"
  11. :locale="{emptyText: '暂无数据'}"
  12. bordered>
  13. <template #handlestatus="{ text }">
  14. <span :class="[text === 1 ? 'success-satus' : 'error-status']">{{ text === 1 ? '正常' : '断开' }}</span>
  15. </template>
  16. </a-table>
  17. </div>
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent, ref, onUnmounted } from 'vue';
  21. import { initData } from '@/setup/methods/index';
  22. import { message } from 'ant-design-vue';
  23. import firstMenu from '@/components/firstMenu/index.vue';
  24. import { GetErmcpOutAccountStatus } from '@/goServiceAPI/ermcp/outaccount-status/index';
  25. import { GetErmcpOutAccountStatus as GetErmcpOutAccountStatusType } from '@/goServiceAPI/ermcp/outaccount-status/interface';
  26. import TimerUtils from '@/utils/tool/timerUtil';
  27. import moment from 'moment';
  28. function getAccountList() {
  29. interface ListType extends GetErmcpOutAccountStatusType {
  30. index: number;
  31. key: string;
  32. }
  33. const columns = [
  34. {
  35. title: '序号',
  36. dataIndex: 'index',
  37. align: 'center',
  38. width: 200,
  39. },
  40. {
  41. title: '资金账号',
  42. align: 'center',
  43. dataIndex: 'accountid',
  44. width: 400,
  45. },
  46. {
  47. title: '期货公司',
  48. align: 'center',
  49. dataIndex: 'fcname',
  50. width: 500,
  51. },
  52. {
  53. title: '连接状态',
  54. align: 'center',
  55. dataIndex: 'handlestatus',
  56. width: 340,
  57. slots: { customRender: 'handlestatus' },
  58. },
  59. ];
  60. const list = ref<ListType[]>([]);
  61. // 更新时间
  62. function getTime(): string {
  63. return moment().format('YYYY-MM-DD HH:mm:ss');
  64. }
  65. const updatedTime = ref<string>(getTime());
  66. // 获取列表
  67. function getAccountStatusList() {
  68. return GetErmcpOutAccountStatus()
  69. .then((res) => {
  70. list.value = res.map((e: GetErmcpOutAccountStatusType, index: number) => {
  71. return { ...e, index: index + 1, key: String(index) };
  72. });
  73. updatedTime.value = getTime();
  74. return 'ok';
  75. })
  76. .catch((e) => {
  77. message.error(e.message);
  78. });
  79. }
  80. // 定时轮询
  81. function setLoop() {
  82. TimerUtils.setInterval(getAccountStatusList, 10000, 'accountStauts');
  83. }
  84. return { columns, list, getAccountStatusList, setLoop, updatedTime };
  85. }
  86. function handleMenu() {
  87. const menulist = [{ key: '1', value: '账号状态' }];
  88. function selectMenu(item: any) {
  89. console.log(item);
  90. }
  91. return { menulist, selectMenu };
  92. }
  93. export default defineComponent({
  94. name: 'account-status',
  95. components: {
  96. firstMenu,
  97. },
  98. setup() {
  99. const { columns, list, getAccountStatusList, setLoop, updatedTime } = getAccountList();
  100. const { menulist, selectMenu } = handleMenu();
  101. initData(async () => {
  102. await getAccountStatusList();
  103. setLoop();
  104. });
  105. onUnmounted(() => {
  106. TimerUtils.clearInterval('accountStauts');
  107. });
  108. return { columns, list, menulist, selectMenu, updatedTime };
  109. },
  110. });
  111. </script>
  112. <style lang="less">
  113. .account-status {
  114. height: 100%;
  115. .ant-table-wrapper {
  116. margin-left: 1px;
  117. .ant-table-body > table {
  118. border: none;
  119. }
  120. .ant-table {
  121. width: 100%;
  122. }
  123. }
  124. .success-satus {
  125. color: #1ff195;
  126. }
  127. .error-status {
  128. color: #ff2b2b;
  129. }
  130. .tip {
  131. padding: 10px 0;
  132. color: #364048;
  133. }
  134. .ant-table-placeholder {
  135. height: 100px;
  136. line-height: 70px;
  137. background: @m-grey9;
  138. border: none;
  139. border-radius: 0px;
  140. }
  141. }
  142. </style>;