imgs.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <route lang="json">
  2. { "style": { "navigationBarTitleText": "个人照片", "navigationBarBackgroundColor": "#fff" } }
  3. </route>
  4. <script setup lang="ts">
  5. import { getDesignerBasicInfo, updateDesignerBasicInfo } from '@/core/libs/agent-requests'
  6. import BottomAppBar from '@/components/bottom-app-bar.vue'
  7. const id = ref()
  8. const formData = ref()
  9. const action = ref(`${import.meta.env.VITE_SERVER_BASEURL}/app-api/infra/file/upload`)
  10. const { data: basicData, run: setBasicData } = useRequest(() => getDesignerBasicInfo(id.value))
  11. const urls = computed(() => {
  12. return basicData.value?.imageUrl && Array.isArray(basicData.value?.imageUrl)
  13. ? basicData.value?.imageUrl
  14. : basicData.value?.imageUrl.split(',')
  15. })
  16. const fileList = computed(() => {
  17. const imgList =
  18. basicData.value?.imageUrl && Array.isArray(basicData.value?.imageUrl)
  19. ? basicData.value?.imageUrl
  20. : basicData.value?.imageUrl.split(',')
  21. return imgList?.map((item: string) => {
  22. return { url: item }
  23. })
  24. })
  25. const submitUpload = async () => {
  26. if (formData.value) {
  27. const { code } = await updateDesignerBasicInfo(
  28. Object.assign({}, { ...basicData.value }, { imageUrl: formData.value }),
  29. )
  30. if (code === 0) {
  31. uni.navigateBack()
  32. }
  33. }
  34. }
  35. const handleChange = ({ fileList }) => {
  36. formData.value = fileList
  37. .map((m: any) => {
  38. if (m.response) {
  39. return JSON.parse(m.response).data
  40. } else {
  41. return m.url
  42. }
  43. })
  44. .join(',')
  45. }
  46. onLoad((query?: Record<string | 'id', string>) => {
  47. if (query?.id) {
  48. id.value = query?.id
  49. setBasicData()
  50. formData.value = basicData.value?.imageUrl
  51. }
  52. })
  53. </script>
  54. <template>
  55. <div class="py-12px pl-16px pr-10px">
  56. <wd-upload
  57. :file-list="fileList"
  58. multiple
  59. image-mode="aspectFill"
  60. :action="action"
  61. @change="handleChange"
  62. ></wd-upload>
  63. <!-- 保存 按钮 -->
  64. <BottomAppBar fixed placeholder>
  65. <wd-button
  66. type="primary"
  67. :round="false"
  68. block
  69. style="backdrop-filter: blur(10px)"
  70. class="mt-20px"
  71. @click="submitUpload"
  72. >
  73. 保存
  74. </wd-button>
  75. </BottomAppBar>
  76. </div>
  77. </template>
  78. <style scoped lang="scss">
  79. ::v-deep .wd-upload {
  80. justify-content: space-between;
  81. }
  82. ::v-deep .wd-upload__preview,
  83. ::v-deep .wd-upload__evoke {
  84. height: 200px !important;
  85. width: 168px !important;
  86. border-radius: 8px !important;
  87. }
  88. </style>