BtnHistoryItemDelete.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <span @click="handleClick" class="btn-delete">
  3. <icon-delete />
  4. <!-- <template v-if="api_status === 1">
  5. <icon-delete color="danger" />
  6. </template>
  7. <template v-if="api_status === 2">
  8. <a-spin />
  9. </template>
  10. <template v-if="api_status === 3">ok</template>
  11. <template v-if="api_status === 4"></template>
  12. <template v-if="api_status === 5"></template> -->
  13. </span>
  14. </template>
  15. <script setup>
  16. import { ref, computed } from 'vue';
  17. import { useI18n } from 'vue-i18n';
  18. import { Modal } from '@arco-design/web-vue';
  19. import { Message } from '@arco-design/web-vue';
  20. import { apiConversationHistoryDelete } from './api-conversation-history';
  21. const props = defineProps({
  22. target_id: String
  23. });
  24. const emits = defineEmits(['deleteSuccess']);
  25. const i18n = useI18n();
  26. // api请求的状态
  27. const api_status = ref(1); // api状态 1 请求未启动 2 请求进心中 3 请求已成功 4 请求失败(网络成功,但是code不等于200) 5 请求出错
  28. const api_message = ref(''); // 请求消息 与 api_status 对应的 message 消息内容
  29. const handleClick = () => {
  30. const msg = i18n.t('conversation.are_you_sure');
  31. const btn_yes = i18n.t('conversation.btn_yes');
  32. const btn_no = i18n.t('conversation.btn_no');
  33. Modal.info({
  34. title: msg,
  35. okText: btn_yes,
  36. cancelText: btn_no,
  37. hideCancel: false,
  38. 'modal-class': 'history-chat-remove-modal',
  39. // content: '删除后无法恢复'
  40. onOk(e) {
  41. // console.log('确定');
  42. // handleConfirmDelete();
  43. },
  44. async onBeforeOk() {
  45. try {
  46. const result = await handleConfirmDeleteV2();
  47. if (result === 200) {
  48. return true;
  49. } else {
  50. // 异常
  51. return false;
  52. }
  53. } catch (err) {
  54. // 出错了
  55. return false;
  56. }
  57. },
  58. onCancel() {
  59. // console.log('取消');
  60. }
  61. });
  62. };
  63. const handleConfirmDeleteV2 = () => {
  64. // 进入加载状态
  65. return new Promise((resolve, reject) => {
  66. apiConversationHistoryDelete(props.target_id)
  67. .then((res) => {
  68. if (res.code / 1 === 200) {
  69. const msg = i18n.t('conversation.del_success');
  70. // 成功
  71. Message.success(msg);
  72. emits('deleteSuccess');
  73. resolve(200);
  74. } else {
  75. // 异常
  76. // api请求成功,但是业务失败
  77. Message.warning(res.msg);
  78. }
  79. })
  80. .catch((err) => {
  81. Message.warning(err.msg);
  82. // api请求出错
  83. reject(err);
  84. });
  85. });
  86. };
  87. const handleConfirmDelete = () => {
  88. // 进入加载状态
  89. api_status.value = 2;
  90. api_message.value = '';
  91. apiConversationHistoryDelete(props.target_id)
  92. .then((res) => {
  93. if (res.code / 1 === 200) {
  94. // 成功
  95. // api请求成功
  96. api_status.value = 3;
  97. api_message.value = 'success';
  98. // Message.success('删除成功');
  99. const msg = i18n.t('conversation.del_success');
  100. // 成功
  101. Message.success(msg);
  102. emits('deleteSuccess');
  103. } else {
  104. // 异常
  105. // api请求成功,但是业务失败
  106. api_status.value = 4;
  107. api_message.value = res.msg;
  108. }
  109. })
  110. .catch((err) => {
  111. // api请求出错
  112. api_status.value = 5;
  113. api_message.value = err.msg;
  114. });
  115. };
  116. </script>
  117. <style lang="css" scoped>
  118. .btn-delete {
  119. color: red;
  120. }
  121. </style>
  122. <style>
  123. .arco-modal.history-chat-remove-modal.arco-modal-simple {
  124. }
  125. .arco-modal.history-chat-remove-modal.arco-modal-simple .arco-modal-header .arco-modal-title {
  126. justify-content: flex-start;
  127. text-align: left;
  128. }
  129. .arco-modal.history-chat-remove-modal.arco-modal-simple .arco-modal-footer {
  130. text-align: right;
  131. margin-top: 0;
  132. }
  133. </style>