Edit.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div x-name="header-edit" class="header-wrapper">
  3. <span class="title">{{ title }}<b />{{ $t(`menu.${router.name}`) }}</span>
  4. <div class="buttons" v-show="show">
  5. <ui-button type="normal" @click.stop="onCancel">{{ $t('common.exit') }}</ui-button>
  6. <ui-button type="primary" @click.stop="onSave">{{ $t('common.save') }}</ui-button>
  7. </div>
  8. </div>
  9. </template>
  10. <script setup>
  11. import { computed } from 'vue'
  12. import { useStore } from 'vuex'
  13. import { Loading, Dialog } from '@kankan/components'
  14. import { getApp, getNum } from '@/app'
  15. import { useI18n } from '@/i18n'
  16. const { t } = useI18n({ useScope: 'global' })
  17. const store = useStore()
  18. const title = computed(() => store.getters['scene/metadata'].title)
  19. const module = computed(() => store.getters.editModule)
  20. const router = computed(() => store.getters.router)
  21. const enterVisible = computed(() => store.getters['tag/enterVisible'])
  22. const show = computed(() => {
  23. // 基础设置的编辑按钮需要特性处理
  24. if (store.getters.toolbar && store.getters.toolbar.show && module.value == 'settings') {
  25. return false
  26. }
  27. return true
  28. })
  29. const onSave = () => {
  30. Loading.show()
  31. store
  32. .dispatch(`${module.value}/save`)
  33. .then(response => {
  34. console.log(response)
  35. Loading.hide()
  36. if (response) {
  37. if (response.success) {
  38. Dialog.toast.hide()
  39. Dialog.toast({ content: t('common.saveSuccess'), type: 'success' })
  40. } else {
  41. Dialog.toast.hide()
  42. Dialog.toast({ content: t('common.busy'), type: 'error' })
  43. }
  44. } else {
  45. }
  46. })
  47. .catch(error => {
  48. console.log(error)
  49. Loading.hide()
  50. if (error) {
  51. // console.error(error)
  52. // Dialog.toast.hide()
  53. Dialog[error.type]({
  54. content: t(error.msg),
  55. type: error.tips,
  56. })
  57. // if (typeof error === 'object' && error.errorMsg) {
  58. // Dialog.toast({ content: '保存失败,' + error.errorMsg, type: 'error' })
  59. // } else {
  60. // Dialog.toast({ content: '保存失败,请重试!', type: 'error' })
  61. // }
  62. }
  63. })
  64. }
  65. const onCancel = () => {
  66. if (router.value.name == 'tag' && enterVisible.value) {
  67. if (!getApp().TagManager.edit.checkNeedSaveTagVisi()) {
  68. store.commit(`${module.value}/cancel`)
  69. return
  70. }
  71. }
  72. if (router.value.name == 'roam') {
  73. if (!getApp().WalkManager.edit.checkNeedSave()) {
  74. store.commit(`${module.value}/cancel`)
  75. return
  76. }
  77. }
  78. Dialog.confirm({
  79. content: t('toast.saveTips'),
  80. title: t('common.tips'),
  81. okText: t('common.confirm'),
  82. noText: t('common.cancel'),
  83. func: state => {
  84. if (state == 'ok') {
  85. store.commit(`${module.value}/cancel`)
  86. }
  87. },
  88. })
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .header-wrapper {
  93. width: 100%;
  94. height: 100%;
  95. display: flex;
  96. align-items: center;
  97. justify-content: center;
  98. }
  99. .title {
  100. font-size: 16px;
  101. white-space: nowrap;
  102. display: flex;
  103. align-items: center;
  104. b {
  105. display: inline-block;
  106. width: 2px;
  107. height: 14px;
  108. margin: 0 10px;
  109. background: rgba(255, 255, 255, 0.16);
  110. }
  111. }
  112. .buttons {
  113. position: absolute;
  114. top: 0;
  115. right: 0;
  116. height: 100%;
  117. display: flex;
  118. align-items: center;
  119. button {
  120. width: 105px;
  121. margin-right: 10px;
  122. }
  123. }
  124. </style>