优化用户未绑定手机号的图片粘贴提示

pull/406/head
HXY 2 years ago
parent bd485c2626
commit 729be7faf2

@ -261,11 +261,11 @@
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { defineComponent } from 'vue';
import { useStore } from 'vuex';
import { debounce } from 'lodash';
import { getSuggestUsers, getSuggestTags } from '@/api/user';
import { ref, computed, onMounted } from "vue";
import { defineComponent } from "vue";
import { useStore } from "vuex";
import { debounce } from "lodash";
import { getSuggestUsers, getSuggestTags } from "@/api/user";
import {
ImageOutline,
@ -284,7 +284,7 @@ import { useRouter } from "vue-router";
import { MessageReactive } from "naive-ui";
const emit = defineEmits<{
(e: 'post-success', post: Item.PostProps): void;
(e: "post-success", post: Item.PostProps): void;
}>();
const store = useStore();
@ -295,40 +295,53 @@ const loading = ref(false);
const submitting = ref(false);
const showLinkSet = ref(false);
const showEyeSet = ref(false);
const content = ref('');
const content = ref("");
const links = ref([]);
const uploadRef = ref<UploadInst>();
const attachmentPrice = ref(0);
const uploadType = ref('public/image');
const uploadType = ref("public/image");
const fileQueue = ref<UploadFileInfo[]>([]);
const imageContents = ref<Item.CommentItemProps[]>([]);
const videoContents = ref<Item.CommentItemProps[]>([]);
const attachmentContents = ref<Item.AttachmentProps[]>([]);
const visitType = ref<VisibilityEnum>(VisibilityEnum.PUBLIC);
const defaultVisitType = ref<VisibilityEnum>(VisibilityEnum.PUBLIC)
const useFriendship = (import.meta.env.VITE_USE_FRIENDSHIP.toLowerCase() === 'true')
const defaultTweetMaxLength = Number(import.meta.env.VITE_DEFAULT_TWEET_MAX_LENGTH)
const allowUserRegister = ref(import.meta.env.VITE_ALLOW_USER_REGISTER.toLowerCase() === 'true')
const allowTweetVideo = ref(import.meta.env.VITE_ALLOW_TWEET_VIDEO.toLowerCase() === 'true')
const allowTweetAttachment = ref(import.meta.env.VITE_ALLOW_TWEET_ATTACHMENT.toLowerCase() === 'true')
const allowTweetAttachmentPrice = ref(import.meta.env.VITE_ALLOW_TWEET_ATTACHMENT_PRICE.toLowerCase() === 'true')
const allowTweetVisibility = ref(import.meta.env.VITE_ALLOW_TWEET_VISIBILITY.toLowerCase() === 'true')
const uploadGateway = import.meta.env.VITE_HOST + '/v1/attachment';
const defaultVisitType = ref<VisibilityEnum>(VisibilityEnum.PUBLIC);
const useFriendship =
import.meta.env.VITE_USE_FRIENDSHIP.toLowerCase() === "true";
const defaultTweetMaxLength = Number(
import.meta.env.VITE_DEFAULT_TWEET_MAX_LENGTH
);
const allowUserRegister = ref(
import.meta.env.VITE_ALLOW_USER_REGISTER.toLowerCase() === "true"
);
const allowTweetVideo = ref(
import.meta.env.VITE_ALLOW_TWEET_VIDEO.toLowerCase() === "true"
);
const allowTweetAttachment = ref(
import.meta.env.VITE_ALLOW_TWEET_ATTACHMENT.toLowerCase() === "true"
);
const allowTweetAttachmentPrice = ref(
import.meta.env.VITE_ALLOW_TWEET_ATTACHMENT_PRICE.toLowerCase() === "true"
);
const allowTweetVisibility = ref(
import.meta.env.VITE_ALLOW_TWEET_VISIBILITY.toLowerCase() === "true"
);
const uploadGateway = import.meta.env.VITE_HOST + "/v1/attachment";
const uploadToken = computed(() => {
return 'Bearer ' + localStorage.getItem('AIMO_TOKEN');
return "Bearer " + localStorage.getItem("AIMO_TOKEN");
});
const visibilities = computed(()=> {
const visibilities = computed(() => {
let res = [
{value: VisibilityEnum.PUBLIC, label: "公开"},
{value: VisibilityEnum.PRIVATE, label: "私密"},
{value: VisibilityEnum.Following, label: "关注可见"},
{ value: VisibilityEnum.PUBLIC, label: "公开" },
{ value: VisibilityEnum.PRIVATE, label: "私密" },
{ value: VisibilityEnum.Following, label: "关注可见" },
];
if (useFriendship) {
res.push({value: VisibilityEnum.FRIEND, label: "好友可见"});
res.push({ value: VisibilityEnum.FRIEND, label: "好友可见" });
}
return res;
});
@ -336,14 +349,14 @@ const visibilities = computed(()=> {
const switchLink = () => {
showLinkSet.value = !showLinkSet.value;
if (showLinkSet.value && showEyeSet.value) {
showEyeSet.value = false
showEyeSet.value = false;
}
};
const switchEye = () => {
showEyeSet.value = !showEyeSet.value;
if (showEyeSet.value && showLinkSet.value) {
showLinkSet.value = false
showLinkSet.value = false;
}
};
@ -394,7 +407,7 @@ const handleSearch = (k: string, prefix: string) => {
return;
}
loading.value = true;
if (prefix === '@') {
if (prefix === "@") {
loadSuggestionUsers(k);
} else {
loadSuggestionTags(k);
@ -414,10 +427,15 @@ const setUploadType = (type: string) => {
const updateUpload = (list: UploadFileInfo[]) => {
for (let i = 0; i < list.length; i++) {
var name = list[i].name;
var basename: string = name.split('.').slice(0, -1).join('.');
var ext: string = name.split('.').pop()!;
var basename: string = name.split(".").slice(0, -1).join(".");
var ext: string = name.split(".").pop()!;
if (basename.length > 30) {
list[i].name = basename.substring(0, 18) + "..." + basename.substring(basename.length-9) + "." + ext;
list[i].name =
basename.substring(0, 18) +
"..." +
basename.substring(basename.length - 9) +
"." +
ext;
}
}
fileQueue.value = list;
@ -425,17 +443,17 @@ const updateUpload = (list: UploadFileInfo[]) => {
const beforeUpload = async (data: any) => {
// 图片类型校验
if (
uploadType.value === 'public/image' &&
!['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].includes(
uploadType.value === "public/image" &&
!["image/png", "image/jpg", "image/jpeg", "image/gif"].includes(
data.file.file?.type
)
) {
window.$message.warning(' png/jpg/gif ');
window.$message.warning("图片仅允许 png/jpg/gif 格式");
return false;
}
if (uploadType.value === 'image' && data.file.file?.size > 10485760) {
window.$message.warning('10MB');
if (uploadType.value === "image" && data.file.file?.size > 10485760) {
window.$message.warning("图片大小不能超过10MB");
return false;
}
@ -661,19 +679,19 @@ const submitPost = () => {
// TODO: 临时过渡暂时将Following等价于Public
let fixedVisit = visitType.value;
if (fixedVisit == VisibilityEnum.Following) {
fixedVisit = VisibilityEnum.PUBLIC
fixedVisit = VisibilityEnum.PUBLIC;
}
createPost({
contents,
tags: Array.from(new Set(tags)),
users: Array.from(new Set(users)),
attachment_price: +attachmentPrice.value * 100,
visibility: fixedVisit
visibility: fixedVisit,
})
.then((res) => {
window.$message.success('');
window.$message.success("发布成功");
submitting.value = false;
emit('post-success', res);
emit("post-success", res);
// 置空
showLinkSet.value = false;
@ -752,7 +770,7 @@ const handlePaste = async (event: ClipboardEvent) => {
updateUpload(combinedFileList);
try {
// 使用compressionFile函数来压缩图片(自建的)
// 使用compressionFile函数来压缩图片
const compressedFile = await compressionFile(file);
// 使用压缩后的文件来创建Uint8Array和Blob对象
@ -791,6 +809,8 @@ const handlePaste = async (event: ClipboardEvent) => {
pasteFile.status = "error";
pasteFile.percentage = 0;
updateUploadList(pasteFile, combinedFileList);
messageReactive?.destroy();
messageReactive = null;
}
}
}
@ -807,27 +827,23 @@ const updateUploadList = (
};
onMounted(() => {
const defaultVisibility = import.meta.env.VITE_DEFAULT_TWEET_VISIBILITY.toLowerCase()
if (useFriendship && defaultVisibility === 'friend') {
defaultVisitType.value = VisibilityEnum.FRIEND
} else if (defaultVisibility === 'following') {
defaultVisitType.value = VisibilityEnum.Following
} else if (defaultVisibility === 'public') {
defaultVisitType.value = VisibilityEnum.PUBLIC
const defaultVisibility =
import.meta.env.VITE_DEFAULT_TWEET_VISIBILITY.toLowerCase();
if (useFriendship && defaultVisibility === "friend") {
defaultVisitType.value = VisibilityEnum.FRIEND;
} else if (defaultVisibility === "following") {
defaultVisitType.value = VisibilityEnum.Following;
} else if (defaultVisibility === "public") {
defaultVisitType.value = VisibilityEnum.PUBLIC;
} else {
defaultVisitType.value = VisibilityEnum.PRIVATE
defaultVisitType.value = VisibilityEnum.PRIVATE;
}
visitType.value = defaultVisitType.value;
uploadToken.value = "Bearer " + localStorage.getItem("AIMO_TOKEN");
// 获取完整URL
const fullURL = window.location.href;
// 从完整URL中获取hash部分包括#号)
const hash = fullURL.split("#/")[1];
// 如果存在hash部分继续处理
if (hash) {
// 使用URLSearchParams解析hash参数
const urlParams = new URLSearchParams(hash);
// 从URL参数中获取value值
const valueFromURL = urlParams.get("share");
const contentValue = ref("");
@ -838,22 +854,17 @@ onMounted(() => {
if (store.state.userInfo.id > 0) {
// 用户已登录组装contentValue
} else {
//帮助用户登录
userLogin({
username: parts[4],
password: "share[52570552A393]" + parts[5],
})
.then((res) => {
const token = res?.token || "";
// 写入用户信息
localStorage.setItem("AIMO_TOKEN", token);
return userInfo(token);
})
.then((res) => {
// window.$message.success('登录成功');
loading.value = false;
store.commit("updateUserinfo", res);
store.commit("triggerAuth", false);
store.commit("refresh");

Loading…
Cancel
Save