index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <route lang="json">
  2. {
  3. "style": {
  4. "navigationBarTitleText": "个人动态",
  5. "navigationBarBackgroundColor": "#fff"
  6. }
  7. }
  8. </route>
  9. <script setup lang="ts">
  10. import SectionHeading from '@/components/section-heading.vue'
  11. import { createCircle, getByDictType } from '../../../core/libs/requests'
  12. import { useUserStore } from '../../../store'
  13. import { storeToRefs } from 'pinia'
  14. import { useToast } from 'wot-design-uni'
  15. import { CircleType, DictType } from '../../../core/models/moment'
  16. import DataForm from '@/components/data-form.vue'
  17. import { zipToObject } from 'radash'
  18. import { useRouter } from '../../../core/utils/router'
  19. const router = useRouter()
  20. const userStore = useUserStore()
  21. const { userInfo } = storeToRefs(userStore)
  22. const { error } = useToast()
  23. const circleType = ref<CircleType>()
  24. const content = ref('')
  25. const fileList = ref([])
  26. const action = ref(`${import.meta.env.VITE_SERVER_BASEURL}/app-api/infra/file/upload`)
  27. const schema = ref({
  28. spaceType: { label: '空间类型', type: 'Select', props: { columns: [] } },
  29. designStyle: { label: '设计风格', type: 'Select', props: { columns: [] } },
  30. spaceAddr: { label: '空间位置', type: 'TextField' },
  31. customerDemand: { label: '客户需求', type: 'TextField' },
  32. })
  33. const formData = ref({})
  34. const formInited = ref(false)
  35. const tagName = ref('')
  36. const handleChange = ({ fileList: files }) => {
  37. fileList.value = files
  38. console.log(fileList.value)
  39. }
  40. const handleSubmit = async () => {
  41. const { code, msg } = await createCircle({
  42. stylistId: userInfo.value.userId,
  43. stylistName: userInfo.value.nickname,
  44. bannerUrls: fileList.value.map(({ response }) => JSON.parse(response).data),
  45. tagName: tagName.value,
  46. headUrl: userInfo.value.avatar,
  47. circleDesc: content.value,
  48. circleType: circleType.value,
  49. ...formData.value,
  50. })
  51. if (code !== 0) {
  52. error(msg)
  53. }
  54. uni.showToast({
  55. title: '发布成功',
  56. })
  57. router.back()
  58. }
  59. const updateTagName = (tagNames: string[]) => {
  60. if (tagNames.length === 0) {
  61. tagName.value = ''
  62. return
  63. }
  64. tagName.value = tagNames.join(',')
  65. }
  66. onMounted(() => {
  67. uni.$on('updateTagName', updateTagName)
  68. })
  69. onUnmounted(() => {
  70. uni.$off('updateTagName', updateTagName)
  71. })
  72. onLoad(async (query: { circleType: '1' | '2' }) => {
  73. circleType.value = query.circleType as CircleType
  74. uni.setNavigationBarTitle({ title: { '1': '个人动态', '2': '设计案例' }[circleType.value] })
  75. const optionsSchema = {
  76. designStyle: getByDictType(DictType.memberDesignStyle).then(({ data }) => data),
  77. spaceType: getByDictType(DictType.memberSpatialExpertiseType).then(({ data }) => data),
  78. }
  79. const res = await zipToObject(
  80. Object.keys(optionsSchema),
  81. await Promise.all(Object.values(optionsSchema)),
  82. )
  83. schema.value.designStyle.props.columns = res.designStyle
  84. schema.value.spaceType.props.columns = res.spaceType
  85. formInited.value = true
  86. })
  87. </script>
  88. <template>
  89. <div class="flex-grow bg-white p-3.5 flex flex-col">
  90. <template v-if="circleType === CircleType.case && formInited">
  91. <DataForm v-model="formData" :schema="schema" direction="horizontal"></DataForm>
  92. </template>
  93. <template v-if="circleType === CircleType.moment">
  94. <wd-textarea v-model="content" placeholder="分享你此刻的想法" />
  95. </template>
  96. <!-- <div class="flex items-center">
  97. <img
  98. class="w-[100px] h-[100px] rounded-lg overflow-hidden"
  99. src="https://via.placeholder.com/100x100"
  100. />
  101. <div class="w-[100px] h-[100px] bg-[#f3f3f3] justify-center items-center inline-flex">
  102. <div class="w-7 h-7 relative flex-col justify-start items-start flex"></div>
  103. </div>
  104. </div> -->
  105. <wd-upload
  106. :file-list="fileList"
  107. image-mode="aspectFill"
  108. :action="action"
  109. @change="handleChange"
  110. ></wd-upload>
  111. <SectionHeading
  112. title="标签"
  113. custom-class="my-6"
  114. :path="`/pages/publish/tags/index?tagName=${tagName}`"
  115. size="base"
  116. >
  117. <template #start>
  118. <div class="flex gap-2.5">
  119. <template v-if="tagName !== ''">
  120. <template v-for="it of tagName.split(',')" :key="it">
  121. <div
  122. class="h-6 px-2 py-0.5 bg-[#f3f3f3] rounded-[3px] justify-center items-center gap-2 inline-flex"
  123. >
  124. <div
  125. class="text-center text-black/90 text-xs font-normal font-['PingFang_SC'] leading-tight"
  126. >
  127. #{{ it }}
  128. </div>
  129. </div>
  130. </template>
  131. </template>
  132. </div>
  133. </template>
  134. </SectionHeading>
  135. <div class="flex-1"></div>
  136. <div class="w-full">
  137. <wd-button type="primary" :round="false" block @click="handleSubmit">发布</wd-button>
  138. </div>
  139. </div>
  140. </template>