publish.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <CommonRoot>
  3. <FlexCol :innerStyle="{
  4. backgroundImage: 'url(https://xy.wenlvti.net/app_static/images/dig/TopBanner.png)',
  5. backgroundSize: '100% auto',
  6. backgroundRepeat: 'no-repeat',
  7. backgroundPosition: 'top center',
  8. minHeight: '100vh',
  9. }">
  10. <StatusBarSpace />
  11. <NavBar title="发布微信贴图" leftButton="back" rightButton="add" />
  12. <FlexCol padding="space.lg">
  13. <ProvideVar
  14. :vars="{
  15. FieldBackgroundColor: 'transparent',
  16. UploaderListAddItemBackgroundImage: 'url(https://xy.wenlvti.net/app_static/images/village/ButtonUpload.png)',
  17. UploaderAddIcon: '',
  18. }"
  19. >
  20. <BackgroundBox
  21. backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxLarge.png"
  22. :backgroundCutBorder="[50,50,50,50]"
  23. :backgroundCutBorderSize="[50,50,50,50]"
  24. direction="column"
  25. gap="gap.md"
  26. :padding="[40, 30]"
  27. >
  28. <Uploader
  29. v-model="images"
  30. listType="grid"
  31. :maxUploadCount="9"
  32. :upload="uploadImage"
  33. />
  34. <Field v-model="title" type="text" placeholder="请输入标题" :maxLength="30" showWordLimit bac />
  35. <Field v-model="content" type="text" multiline placeholder="请输入内容" :maxLength="1000" rows="10" showWordLimit />
  36. </BackgroundBox>
  37. </ProvideVar>
  38. <Height :height="50" />
  39. <ImageButton
  40. src="https://xy.wenlvti.net/app_static/images/village/ButtonPrimary.png"
  41. text="发布"
  42. width="500rpx"
  43. height="80rpx"
  44. @click="publish"
  45. />
  46. </FlexCol>
  47. <BackgroundBox
  48. position="fixed" :inset="{ b: 0, l: 0, r: 0 }"
  49. backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxLarge.png"
  50. :backgroundCutBorder="[50,50,0,50]"
  51. :backgroundCutBorderSize="[50,50,0,50]"
  52. direction="column"
  53. :padding="[20, 10]"
  54. >
  55. <FlexRow padding="space.md" align="center" justify="space-between">
  56. <FlexRow align="center" justify="center">
  57. <Button icon="https://xy.wenlvti.net/app_static/images/village/IconAi.png" @click="showAgentPopup = true">AI伴写</Button>
  58. </FlexRow>
  59. <FlexRow align="center" justify="center">
  60. <IconButton
  61. icon="setting"
  62. width="40rpx"
  63. height="40rpx"
  64. />
  65. </FlexRow>
  66. </FlexRow>
  67. <XBarSpace />
  68. </BackgroundBox>
  69. </FlexCol>
  70. <Popup v-model:show="showAgentPopup" position="bottom" closeable size="60vh" round>
  71. <Agent />
  72. </Popup>
  73. </CommonRoot>
  74. </template>
  75. <script setup lang="ts">
  76. import { onMounted, ref, watch } from 'vue';
  77. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  78. import { Debounce } from '@imengyu/imengyu-utils';
  79. import { confirm } from '@/components/dialog/CommonRoot';
  80. import CommonContent from '@/api/CommonContent';
  81. import CommonRoot from '@/components/dialog/CommonRoot.vue';
  82. import BackgroundBox from '@/components/display/block/BackgroundBox.vue';
  83. import Field from '@/components/form/Field.vue';
  84. import Uploader from '@/components/form/Uploader.vue';
  85. import FlexCol from '@/components/layout/FlexCol.vue';
  86. import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
  87. import NavBar from '@/components/nav/NavBar.vue';
  88. import ProvideVar from '@/components/theme/ProvideVar.vue';
  89. import type { UploaderAction } from '@/components/form/Uploader';
  90. import Height from '@/components/layout/space/Height.vue';
  91. import ImageButton from '@/components/basic/ImageButton.vue';
  92. import FlexRow from '@/components/layout/FlexRow.vue';
  93. import Button from '@/components/basic/Button.vue';
  94. import XBarSpace from '@/components/layout/space/XBarSpace.vue';
  95. import IconButton from '@/components/basic/IconButton.vue';
  96. import Popup from '@/components/dialog/Popup.vue';
  97. import Agent from './agent.vue';
  98. const { querys } = useLoadQuerys({
  99. tag: '',
  100. villageId: 0,
  101. });
  102. const title = ref('');
  103. const content = ref('');
  104. const images = ref([] as string[]);
  105. const showAgentPopup = ref(false);
  106. const saveDraftDebunce = new Debounce(1000, () => {
  107. uni.setStorageSync('postDraft', {
  108. title: title.value,
  109. content: content.value,
  110. images: images.value,
  111. });
  112. });
  113. watch(title, () => saveDraftDebunce.executeWithDelay());
  114. watch(content, () => saveDraftDebunce.executeWithDelay());
  115. watch(images, () => saveDraftDebunce.executeWithDelay());
  116. function loadDraft() {
  117. const draft = uni.getStorageSync('postDraft');
  118. if (draft) {
  119. confirm({
  120. content: '您有上次编辑未完成的草稿,是否要从上次的编辑数据继续?',
  121. confirmText: '继续',
  122. cancelText: '取消',
  123. }).then((res) => {
  124. if (res) {
  125. title.value = draft.title;
  126. content.value = draft.content;
  127. images.value = draft.images;
  128. }
  129. });
  130. }
  131. }
  132. function uploadImage(item: UploaderAction) {
  133. item.onStart('正在上传');
  134. let task: UniApp.UploadTask | null = null;
  135. CommonContent.uploadFile(item.item.filePath, 'image', 'file', undefined, (_task) => {
  136. task = _task;
  137. task.onProgressUpdate((res) => {
  138. item.onProgress(res.progress);
  139. });
  140. })
  141. .then((res) => {
  142. item.onFinish({
  143. uploadedUrl: res.fullurl,
  144. previewUrl: res.fullurl,
  145. }, '上传成功');
  146. })
  147. .catch((err) => {
  148. item.onError(err);
  149. });
  150. return () => {
  151. task?.abort();
  152. };
  153. }
  154. function publish() {
  155. console.log('publish', title.value, content.value, images.value);
  156. }
  157. onMounted(() => {
  158. loadDraft();
  159. setTimeout(() => {
  160. showAgentPopup.value = true;
  161. }, 1000);
  162. });
  163. </script>