ChangeNickDialog.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <CommonDialog v-model:show="show" title="修改昵称" :showDivider="false">
  3. <FlexCol gap="gap.lg" padding="padding.md" width="600rpx">
  4. <Text textAlign="center" text="修改您在本村的昵称,可以方便大家认识您" fontConfig="contentSpeicalText" />
  5. <Height :height="10" />
  6. <Field v-model="name" placeholder="请输入昵称" type="text" showWordLimit :maxLength="30" />
  7. <Height :height="20" />
  8. <FlexRow justify="space-around" gap="gap.md">
  9. <FrameButton text="返回" @click="show = false" width="220rpx" />
  10. <FrameButton primary text="提交" @click="addSubmit" :loading="submiting" width="220rpx" />
  11. </FlexRow>
  12. </FlexCol>
  13. </CommonDialog>
  14. </template>
  15. <script setup lang="ts">
  16. import { ref } from 'vue';
  17. import { toast } from '@/components/dialog/CommonRoot';
  18. import { showError } from '@/common/composeabe/ErrorDisplay';
  19. import { useVillageStore } from '@/store/village';
  20. import CommonDialog from '@/common/components/CommonDialog.vue';
  21. import FrameButton from '@/common/components/FrameButton.vue';
  22. import Text from '@/components/basic/Text.vue';
  23. import FlexCol from '@/components/layout/FlexCol.vue';
  24. import FlexRow from '@/components/layout/FlexRow.vue';
  25. import Height from '@/components/layout/space/Height.vue';
  26. import Field from '@/components/form/Field.vue';
  27. import LightVillageApi from '@/api/light/LightVillageApi';
  28. const show = ref(false);
  29. const props = defineProps<{
  30. villageId: number;
  31. currentNick?: string;
  32. }>();
  33. const emit = defineEmits(['finish']);
  34. const villageStore = useVillageStore();
  35. const submiting = ref(false);
  36. const name = ref('');
  37. async function addSubmit() {
  38. try {
  39. submiting.value = true;
  40. await LightVillageApi.nicknameSave({
  41. villageId: props.villageId,
  42. villageNickname: name.value,
  43. });
  44. toast({ content: '提交成功' });
  45. show.value = false;
  46. villageStore.loadMyJoinedVillages();
  47. setTimeout(() => {
  48. villageStore.reloadVillageInfo();
  49. }, 500);
  50. } catch (e) {
  51. showError(e);
  52. } finally {
  53. submiting.value = false;
  54. }
  55. }
  56. defineExpose({
  57. show: () => {
  58. show.value = true;
  59. name.value = props.currentNick || '';
  60. },
  61. });
  62. </script>