chenqy 2 years ago
parent fb0d9547f8
commit 7f0f44aad7

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -1,6 +1,6 @@
class UserDto {
export class UserDto {
id?: number;
openId?: string
openid?: string
nickname?: string;
avatar?: string;
birth?: string;

@ -4,6 +4,7 @@ import { diskStorage } from 'multer';
import path, { extname } from 'path';
import { base_url } from '../utils/config/index'
import { InvalidFileTypeException, FileTooLargeException, EmptyFileException } from '../error/fileError';
import { AuthInterceptor } from 'src/interceptor/auth.interceptor';
@Controller('upload')
@ -12,6 +13,7 @@ export class FileUploadController {
@Post('img')
@UseInterceptors(
AuthInterceptor,
FileInterceptor('img', {
fileFilter(req, file, callback) {
// 检查图片类型
@ -26,7 +28,11 @@ export class FileUploadController {
callback(null, true)
},
storage: diskStorage({
destination: './public/temp/img',
destination: (req, file, callback) => {
const pic_type = req.body.pic_type;
console.log(pic_type);
callback(null, `./public/img/${pic_type}`);
},
filename(req, file, callback) {
const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join('');
callback(null, `${randomName}${extname(file.originalname)}`);
@ -34,7 +40,7 @@ export class FileUploadController {
})
})
)
async uploadImage(@UploadedFile() file) {
uploadImage(@UploadedFile() file) {
if (!file) {
throw new EmptyFileException();
}
@ -48,44 +54,4 @@ export class FileUploadController {
}
// 多图上传
@Post('imgs')
@UseInterceptors(
FilesInterceptor('imgs', 9, {
fileFilter(req, file, callback) {
// 检查图片类型
const allowedMimes = ['image/jpeg', 'image/png', 'image/gif'];
if (!allowedMimes.includes(file.mimetype)) {
callback(new InvalidFileTypeException('图片'), false)
}
// 检查图片大小
if (file.size > 2 * 1024 * 1024) {
callback(new FileTooLargeException(), false)
}
callback(null, true)
},
storage: diskStorage({
destination: './public/temp/img',
filename(req, file, callback) {
const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join('');
callback(null, `${randomName}${extname(file.originalname)}`);
}
})
})
)
async uploadImages(@UploadedFiles() files) {
if (!files) {
throw new EmptyFileException();
}
console.log(files);
const paths = files.map(file => {
const changePath = file.path.replace(/\\/g, '/').replace('public/', '/');
return base_url + '/static' + changePath
})
return paths;
}
}

@ -33,6 +33,11 @@ export class PostController {
}
try {
await this.postService.createCommonShare(commonShare);
// 获取图片名称
const pic_list = body.pic_list.map(item => item.url.split('/').pop());
// 将/public/temp/img 下的图片移动到 /public/commonshare/img
return 'common share 上传成功';
} catch (error) {
console.log(error);

@ -1,6 +1,7 @@
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
import { Body, Controller, Head, Headers, Post, UseInterceptors } from '@nestjs/common';
import { UserService } from './user.service';
import { AuthInterceptor } from 'src/interceptor/auth.interceptor';
import { UserDto } from 'src/dto/user/user';
@Controller('user')
export class UserController {
@ -31,12 +32,28 @@ export class UserController {
return user;
}
// {
// openId: 'oyBXy5ZPz7etmnwy34TICz2QT0O4',
// sessionKey: 'xj7jGKXKTZ1IefZ3OJBS0A=='
// }
// avatar
// {
// avatar: 'http://localhost:3000/api/v1/static/img/avatar/3a386d7b50a98aab5b10bdc3102bb323e4.jpg'
// }
//修改用户信息
@UseInterceptors(AuthInterceptor)
@Post('updateuser')
async updateUser(@Body() userDto: UserDto) {
console.log(userDto);
return 'ok'
async updateUser(@Headers() Header, @Body() body) {
// from header get openId and sessionKey
const openId = Header.openid
const avatar = body.avatar
const userDto: UserDto = {
openid: openId,
avatar: avatar
}
return await this.userService.updateUser(userDto)
}
}

@ -1,7 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { UserDto } from 'src/dto/user/user';
import { PrismaService } from 'src/prisma/prisma.service';
import { getSessionKey, setUserLoginMap, hasUser, deleteUser } from 'src/store/index'
const S = 1000
@Injectable()
@ -61,5 +64,16 @@ export class UserService {
return user
}
//update
async updateUser(userDto: UserDto) {
const user = await this.prismaService.user.update({
where: {
openid: userDto.openid
},
data: userDto
})
return user
}
}

@ -0,0 +1,7 @@
import fs from 'fs';
function moveFile() {
fs.rename('./test.jpg', './public/img/commonShare/test.jpg', (res) => {
console.log(res);
});
}

@ -0,0 +1,10 @@
const fs = require('fs');
const path = require('path');
function moveFile() {
fs.rename('./test.jpg', './public/img/commonShare/test.jpg', (res) => {
console.log(res);
});
}
moveFile();

@ -55,9 +55,6 @@ dependencies:
pinia:
specifier: 2.0.33
version: registry.npmmirror.com/pinia@2.0.33(vue@3.2.45)
remixicon:
specifier: ^3.5.0
version: registry.npmmirror.com/remixicon@3.5.0
sass:
specifier: ^1.66.1
version: registry.npmmirror.com/sass@1.66.1
@ -7145,12 +7142,6 @@ packages:
jsesc: registry.npmmirror.com/jsesc@0.5.0
dev: true
registry.npmmirror.com/remixicon@3.5.0:
resolution: {integrity: sha512-wNzWGKf4frb3tEmgvP5shry0n1OdTjjEk9RHLuRuAhfA50bvEdpKH1XWNUYrHUSjAQQkkdyIm+lf4mOuysIKTQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/remixicon/-/remixicon-3.5.0.tgz}
name: remixicon
version: 3.5.0
dev: false
registry.npmmirror.com/require-directory@2.1.1:
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz}
name: require-directory

@ -0,0 +1,81 @@
<template>
<view
:animation="animation_data"
class="mask"
@click="click_mask"
v-if="mask_show"
>
</view>
<view
class="main-content"
:style="{
transform: modelValue ? 'translateY(0)' : 'translateY(100%)',
...custom_style,
}"
>
<slot></slot>
</view>
</template>
<script setup>
import { defineEmits, ref, watch } from "vue";
const props = defineProps({
modelValue: {
type: Boolean,
default: false,
},
custom_style: {
type: Object,
},
maskClose: {
type: Boolean,
default: true,
},
});
const animation_data = ref({});
const mask_show = ref(false);
watch(
() => props.modelValue,
(newVal) => {
mask_show.value = newVal;
},
{
immediate: true,
}
);
const emit = defineEmits(["update:modelValue"]);
const click_mask = () => {
if (!props.maskClose) {
return;
}
emit("update:modelValue", false);
};
</script>
<style lang="scss" scoped>
.mask {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100%;
background-color: rgba(0, 0, 0, 0.1);
z-index: 9998;
}
.main-content {
z-index: 9999;
position: fixed;
box-sizing: border-box;
transform: translateY(100%);
bottom: 0;
left: 0;
width: 100vw;
height: max-content;
transition: all 0.4s ease;
}
</style>

@ -1,7 +1,7 @@
{
"pages": [
{
"path": "pages/setting/userSetting",
"path": "pages/function/function",
"style": {
"navigationStyle": "custom"
}
@ -12,6 +12,13 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/setting/userSetting",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/learn/learn",
"style": {
@ -45,14 +52,6 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/function/function",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/verify/verify",
"style": {

@ -26,10 +26,7 @@
v-if="loginStatus"
width="50px"
height="50px"
:img-src="
avatar ||
'/static/icon/user.png'
"
:img-src="avatar || '/static/icon/user.png'"
radius="50%"
></LazyImg>
<LazyImg
@ -43,10 +40,8 @@
<view class="person-name"> {{ nickname || "微信用户" }} </view>
<view class="time-record"> 加入老友16天 </view>
</view>
<view class="login-area" v-else>
<view class="login-btn" @click="linkTo('/pages/verify/login')"
>立即登陆</view
>
<view class="login-area" @click="linkTo('/pages/verify/login')" v-else>
<view class="login-btn">立即登陆</view>
<view class="tip"> 期待与你相见我的挚友 </view>
</view>
<image class="icon" src="/static/svg/right.svg" mode="aspectFit">
@ -92,22 +87,19 @@
</template>
<script setup>
import SmallButton from "../../component/button/smallButton.vue";
import LazyImg from "../../component/lazyImg/lazyImg.vue";
import { todo } from "../../utils/index.js";
import { onReady } from "@dcloudio/uni-app";
import { ref, watch } from "vue";
import CustomBlock from "../../component/block/customBlock.vue";
import { useUserStore } from "../../store/index";
import { storeToRefs } from "pinia";
import { linkTo } from "../../utils/index.js";
import { ref } from "vue";
import CustomBlock from "../../component/block/customBlock.vue";
import SmallButton from "../../component/button/smallButton.vue";
import LazyImg from "../../component/lazyImg/lazyImg.vue";
import { useUserStore } from "../../store";
import { linkTo, todo } from "../../utils/index.js";
// userStore
const userStore = useUserStore();
const { nickname, avatar, _sessionKey, loginStatus } = storeToRefs(userStore);
const show_loading = ref(false);
const other_record = [
{
name: "主题",
@ -166,6 +158,7 @@ onReady(() => {
.top-header {
display: flex;
justify-content: flex-end;
border: 1px solid red;
}
.personal-info-block {
display: flex;

@ -22,7 +22,7 @@ import TopTabBar from "../../component/topTabBar/topTabBar.vue";
import Card from "../../component/card/card.vue";
import { onReady, onShow, onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
import { baseUrl } from "../../utils/config";
import { baseUrl } from "../../utils/api";
import { useHomeStore, useUserStore } from "../../store";
import { storeToRefs } from "pinia";
import { linkTo } from "../../utils";
@ -35,14 +35,14 @@ const menu_button_pos = ref({
top: 0,
});
onShow(() => {});
onShow(() => {
homeStore._get_common_share_list();
});
onReady(() => {
const res = uni.getMenuButtonBoundingClientRect();
menu_button_pos.value.top = res.top;
menu_button_pos.value.height = res.height;
query();
});
const redirectToPost = (idx) => {
@ -50,40 +50,6 @@ const redirectToPost = (idx) => {
linkTo("/pages/post/post");
};
// query
const query = () => {
uni.request({
url: baseUrl + "/post/get/commonshare",
method: "GET",
data: {
page: 1,
size: 10,
},
success: (res) => {
console.log(res);
if (res.statusCode == 200) {
common_share_list.value = [
...common_share_list.value,
...res.data.map((item) => {
return {
title: item.title,
cover_url: item.cover,
like: item.like,
author: {
name: item.nickname,
avatar: item.avatar,
},
};
}),
];
}
},
fail: (err) => {
console.log(err);
},
});
};
//query share
</script>
<style lang="scss" scoped>

@ -1,6 +1,7 @@
<template>
<view class="main-content">
<Header title="设置"></Header>
<button @click="linkTo('/pages/setting/userSetting')"></button>
<button class="btn-logout" @click="login_out">退</button>
</view>
<CommonLoading :show="show_loading"></CommonLoading>
@ -8,13 +9,17 @@
<script setup>
import { ref } from "vue";
import { useUserStore } from "../../store";
import { useUserStore ,useCommonStore} from "../../store";
import CommonLoading from "../../component/loading/commonLoading.vue";
import Header from "../../component/header/header.vue";
import { storeToRefs } from 'pinia'
import { linkTo } from '../../utils'
const userStore = useUserStore();
const commonStore = useCommonStore();
const { show_loading } = storeToRefs(commonStore);
const show_loading = ref(false);
// function
const login_out = () => {

@ -4,13 +4,17 @@
<CloseBox></CloseBox>
<view class="user-details">
<view class="avatar-area" @click="change_avatar">
<image class="avatar" src="/static/icon/user.png" mode="aspectFit">
<image
class="avatar"
:src="avatar || '/static/icon/user.png'"
mode="aspectFill"
>
</image>
<image class="edit" src="/static/svg/right.svg" mode="aspectFit">
</image>
</view>
<!-- nickname -->
<view class="edit-area">
<view class="edit-area" @click="open_drawer">
<view class="edit-name"> 昵称 </view>
<view class="edit-content">
{{ nickname || "微信用户" }}
@ -49,17 +53,28 @@
</view>
</view>
</view>
<Drawer v-model="show_drawer">
<view class="drawer-area">
<input type="nickname" class="weui-input" placeholder="请输入昵称" />
</view>
</Drawer>
</template>
<script setup>
import Header from "../../component/header/header.vue";
import CloseBox from "../../component/box/closeBox.vue";
import { useUserStore } from "../../store/index";
import { ref } from "vue";
import { storeToRefs } from "pinia";
import { uploadImg } from "../../utils/http";
import CloseBox from "../../component/box/closeBox.vue";
import Header from "../../component/header/header.vue";
import { useUserStore } from "../../store";
import Drawer from "../../component/drawer/drawer.vue";
const userStore = useUserStore();
const { nickname } = storeToRefs(userStore);
const { nickname, avatar } = storeToRefs(userStore);
const show_drawer = ref(false);
const open_drawer = () => {
show_drawer.value = true;
};
const change_avatar = () => {
uni.showActionSheet({
@ -71,9 +86,7 @@ const change_avatar = () => {
sizeType: ["original", "compressed"],
sourceType: ["camera"],
success: (res) => {
uploadImg(res.tempFilePaths[0]).then((res) => {
console.log(res);
});
userStore._update_user_avatar(res.tempFilePaths[0]);
},
});
} else if (res.tapIndex == 1) {
@ -82,9 +95,7 @@ const change_avatar = () => {
sizeType: ["original", "compressed"],
sourceType: ["album"],
success: (res) => {
uploadImg(res.tempFilePaths[0]).then((res) => {
console.log(res);
});
userStore._update_user_avatar(res.tempFilePaths[0]);
},
});
}
@ -94,6 +105,12 @@ const change_avatar = () => {
</script>
<style lang="scss" scoped>
.drawer-area {
height: 60vh;
border: 1px solid red;
background-color: #fefefe;
}
.main-content {
height: 100vh;
background-color: #f4f4f4;

@ -68,10 +68,9 @@ import SmallButton from "../../component/button/smallButton.vue";
import Header from "../../component/header/header.vue";
import LazyImg from "../../component/lazyImg/lazyImg.vue";
import CommonLoading from "../../component/loading/commonLoading.vue";
import { useCommonShareStore } from "../../store";
import { useCommonShareStore, useCommonStore } from "../../store";
import { uploadImg } from "../../utils/http";
const props = defineProps({
height: {
type: String,
@ -82,8 +81,8 @@ const props = defineProps({
const commonShareStore = useCommonShareStore();
const { pic_id, pic_list, common_share_content, common_share_title } =
storeToRefs(commonShareStore);
const show_loading = ref(false);
const commonStore = useCommonStore();
const { show_loading } = storeToRefs(commonStore);
const PIC_LIMIT_SIZE = 9;
@ -101,9 +100,7 @@ const add_pic = () => {
sourceType: ["album"], //album camera 使
success: (res) => {
res.tempFilePaths.forEach((item) => {
uploadImg(item).then((res) => {
commonShareStore._add_pic(res.data);
});
commonShareStore._add_pic(item);
});
},
});

@ -39,8 +39,9 @@ import { storeToRefs } from "pinia";
import { ref } from "vue";
import {
useCommonShareStore,
useUserStore,
useVidoShareStore,
useUserStore,
useCommonStore,
} from "../../store";
import CommonShare from "./commonShare.vue";
import VideoShare from "./videoShare.vue";
@ -49,16 +50,18 @@ import { linkTo } from "../../utils/index";
// store
const userStore = useUserStore();
const commonStore = useCommonShareStore();
const commonShareStore = useCommonShareStore();
const videoStore = useVidoShareStore();
const commonStore = useCommonStore();
const { _openid, _sessionKey } = storeToRefs(userStore);
const { commonShare_is_empty } = storeToRefs(commonStore);
const { commonShare_is_empty, commonShare_is_not_complete } =
storeToRefs(commonShareStore);
const { videoShare_is_empty } = storeToRefs(videoStore);
const { show_loading } = storeToRefs(commonStore);
const choose_type_component = ref("");
const footerHeight = ref("16");
const show_loading = ref(false);
const share_type_list = ref([
{
@ -107,7 +110,7 @@ const changeChangeShareType = (idx) => {
itemList: ["清空数据"],
success: (choose_idx) => {
//
commonStore._clear_data();
commonShareStore._clear_data();
videoStore._clear_data();
share_type_list.value.forEach((item, i) => {
@ -136,18 +139,47 @@ const changeChangeShareType = (idx) => {
};
//
const commit_share = () => {
switch (choose_type_component.value) {
case "CommonShare":
if (commonShare_is_empty.value) {
uni.showToast({
title: "请填写内容",
icon: "none",
});
return;
}
show_loading.value = true;
commonStore._post_commonshare().then((res) => {
// const commit_share = () => {
// switch (choose_type_component.value) {
// case "CommonShare":
// show_loading.value = true;
// commonShareStore
// .post_commonshare()
// .then((res) => {
// show_loading.value = false;
// uni.showToast({
// title: "",
// icon: "none",
// });
// setTimeout(() => {
// linkTo("/pages/index/index", true);
// }, 1000);
// })
// .catch((err) => {
// show_loading.value = false;
// console.log(err);
// // uni.showToast({
// // title: err,
// // icon: "none",
// // });
// });
// break;
// case "VideoShare":
// uni.showToast({
// title: "",
// icon: "none",
// });
// break;
// }
// };
const commit_share = async () => {
try {
switch (choose_type_component.value) {
case "CommonShare":
show_loading.value = true;
await commonShareStore.post_commonshare();
show_loading.value = false;
uni.showToast({
title: "发布成功",
@ -156,17 +188,20 @@ const commit_share = () => {
setTimeout(() => {
linkTo("/pages/index/index", true);
}, 1000);
// setTimeout(() => {
// uni.navigateBack();
// }, 1000);
});
break;
case "VideoShare":
uni.showToast({
title: "功能未开发",
icon: "none",
});
break;
break;
case "VideoShare":
uni.showToast({
title: "功能未开发",
icon: "none",
});
break;
}
} catch (err) {
show_loading.value = false;
uni.showToast({
title: err.toString().slice(6),
icon: "none",
});
}
};
</script>

@ -31,25 +31,28 @@
<script setup>
import { ref } from "vue";
import { useUserStore } from "../../store";
import { useUserStore ,useCommonStore} from "../../store";
import CommonLoading from "../../component/loading/commonLoading.vue";
import Header from "../../component/header/header.vue";
import { storeToRefs } from 'pinia'
const userStore = useUserStore();
const show_loading = ref(false);
const commonStore = useCommonStore();
const { show_loading } = storeToRefs(commonStore);
const login = () => {
commonStore.show_loading_open();
show_loading.value = true;
userStore
.loginByWx()
.then((res) => {
show_loading.value = false;
commonStore.show_loading_close();
uni.switchTab({
url: "/pages/index/index",
});
})
.catch((err) => {
show_loading.value = false;
commonStore.show_loading_close();
uni.showToast({
title: "登陆失败",
icon: "none",

@ -1,3 +1,4 @@
export * from "./modules/user";
export * from "./modules/user/index";
export * from "./modules/share";
export * from "./modules/home";
export * from "./modules/common";

@ -0,0 +1,19 @@
import { defineStore } from "pinia";
import { ref } from 'vue'
export const useCommonStore = defineStore("common", () => {
const show_loading = ref(false);
const show_loading_close = () => {
show_loading.value = false;
};
const show_loading_open = () => {
show_loading.value = true;
};
return {
show_loading,
show_loading_close,
show_loading_open,
};
});

@ -19,11 +19,11 @@ export const useHomeStore = defineStore("home", () => {
page: 1,
size: 10,
},
timeout: 3000,
success: (res) => {
console.log(res);
if (res.statusCode == 200) {
common_share_list.value = [
...common_share_list.value,
...res.data.map((item) => {
return {
title: item.title,
@ -39,6 +39,12 @@ export const useHomeStore = defineStore("home", () => {
}
},
fail: (err) => {
uni.showToast({
title: "获取图文分享列表失败",
icon: "none",
duration: 2000,
});
console.log(err);
},
});

@ -1,10 +1,13 @@
import { defineStore } from "pinia";
import { defineStore, storeToRefs } from "pinia";
import { ref, computed } from "vue";
import { baseUrl } from "../../../utils/config";
import { useUserStore } from "../../index";
import { storeToRefs } from "pinia";
import { baseUrl } from "../../../utils/api";
const SuccessCode = 201;
export const useCommonShareStore = defineStore("commonShare", () => {
const userStore = useUserStore();
const { _openid, _sessionKey, avatar, nickname } = storeToRefs(userStore);
const pic_id = ref(0);
const pic_list = ref([]);
const common_share_title = ref("");
@ -19,6 +22,15 @@ export const useCommonShareStore = defineStore("commonShare", () => {
);
});
// 数据不完整
const commonShare_is_not_complete = computed(() => {
return (
pic_list.value.length === 0 ||
common_share_title.value === "" ||
common_share_content.value === ""
);
});
const commonshare_totalData = computed(() => {
return {
pic_list: pic_list.value,
@ -28,9 +40,141 @@ export const useCommonShareStore = defineStore("commonShare", () => {
});
//function
const _post_commonshare = () => {
const userStore = useUserStore();
const { _openid, _sessionKey, avatar, nickname } = storeToRefs(userStore);
// const _commit_pic_list = () => {
// const total_cnt = pic_list.value.length;
// return new Promise((resolve, reject) => {
// pic_list.value.forEach((item, idx) => {
// uni.uploadFile({
// url: baseUrl + "/upload/img",
// filePath: item.url,
// name: "img",
// header: {
// openId: _openid.value,
// sessionKey: _sessionKey.value,
// },
// formData: {
// pic_type: "commonshare",
// },
// timeout: 3000,
// success: (res) => {
// if (res.code == 400) {
// reject(res.errMsg);
// }
// pic_list.value[idx].url = res.data;
// if (idx == total_cnt - 1) {
// resolve();
// }
// },
// fail: (err) => {
// reject();
// },
// });
// });
// });
// };
// const _post_commonshare_ = () => {
// return new Promise((resolve, reject) => {
// uni.request({
// url: baseUrl + "/post/add/commonshare",
// method: "POST",
// header: {
// openId: _openid.value,
// sessionKey: _sessionKey.value,
// },
// data: {
// pic_list: pic_list.value,
// common_share_title: common_share_title.value,
// common_share_content: common_share_content.value,
// nickname: nickname.value,
// avatar: avatar.value,
// like: 1314,
// },
// timeout: 3000,
// success: (res) => {
// if (res.code == 400) {
// reject(res.errMsg);
// }
// resolve(res);
// },
// fail: (err) => {
// reject(err);
// },
// });
// });
// };
// const post_commonshare = () => {
// // 判断是否登陆
// return new Promise(async (resolve, reject) => {
// if (!_openid.value || !_sessionKey.value) {
// reject("请先登陆");
// return;
// }
// if (commonShare_is_not_complete.value) {
// reject("数据不完整");
// return;
// }
// _commit_pic_list()
// .then(() => {
// _post_commonshare_()
// .then((res) => {
// resolve(res);
// })
// .catch((err) => {
// uni.showToast({
// title: "上传失败",
// icon: "none",
// duration: 2000,
// });
// reject(err);
// });
// })
// .catch((err) => {
// uni.showToast({
// title: "上传失败",
// icon: "none",
// duration: 2000,
// });
// reject(err);
// });
// });
// };
const _commit_pic_list = () => {
const uploadPromises = pic_list.value.map((item, idx) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + "/upload/img",
filePath: item.url,
name: "img",
header: {
openId: _openid.value,
sessionKey: _sessionKey.value,
},
formData: {
pic_type: "commonshare",
},
timeout: 3000,
success: (res) => {
if (res.statusCode === SuccessCode) {
pic_list.value[idx].url = res.data;
resolve();
} else {
reject(`Upload failed with status code ${res.statusCode}`);
}
},
fail: (err) => {
reject(`Upload failed: ${err}`);
},
});
});
});
return Promise.all(uploadPromises);
};
const _post_commonshare_ = () => {
return new Promise((resolve, reject) => {
uni.request({
url: baseUrl + "/post/add/commonshare",
@ -47,16 +191,40 @@ export const useCommonShareStore = defineStore("commonShare", () => {
avatar: avatar.value,
like: 1314,
},
timeout: 3000,
success: (res) => {
resolve(res);
if (res.statusCode === SuccessCode) {
resolve(res);
} else {
reject(`Request failed with status code ${res.statusCode}`);
}
},
fail: (err) => {
reject(err);
reject(`Request failed: ${err}`);
},
});
});
};
const post_commonshare = async () => {
try {
if (!_openid.value || !_sessionKey.value) {
throw new Error("请先登陆");
}
if (commonShare_is_not_complete.value) {
throw new Error("数据不完整");
}
await _commit_pic_list();
console.log(123321);
const res = await _post_commonshare_();
console.log(res);
return res;
} catch (error) {
throw error;
}
};
const _add_pic = (pic) => {
pic_list.value.push({
id: pic_id.value++,
@ -83,7 +251,9 @@ export const useCommonShareStore = defineStore("commonShare", () => {
common_share_content,
commonShare_is_empty,
commonshare_totalData,
_post_commonshare,
commonShare_is_not_complete,
_commit_pic_list,
post_commonshare,
_add_pic,
_del_pic,
_clear_data,

@ -1,9 +1,11 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { wxLogin } from "../../utils/verify/wxLogin";
import { baseUrl } from "../../utils/config";
import { wxLogin } from "../../../utils/verify/wxLogin";
import { baseUrl } from "../../../utils/api";
const useUserStore = defineStore("user", () => {
const successCode = 201;
export const useUserStore = defineStore("user", () => {
const _openid = ref("");
const _sessionKey = ref("");
const nickname = ref("");
@ -79,9 +81,61 @@ const useUserStore = defineStore("user", () => {
loginStatus.value = false;
};
//修改avatar
const _update_user_avatar = (avatarUrl) => {
console.log('123123');
//上传头像图片
const _upload_avatar = (avatarUrl) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + "/upload/img",
filePath: avatarUrl,
name: "img",
header: {
openId: _openid.value,
sessionKey: _sessionKey.value,
},
formData: {
pic_type: "avatar",
},
timeout: 3000,
success: (res) => {
console.log(res);
if (res.statusCode !== successCode) {
reject(res.errMsg);
}
avatar.value = res.data;
resolve(res);
},
fail: (err) => {
reject(err);
},
});
});
};
const _update_user_avatar = async (avatarUrl) => {
await _upload_avatar(avatarUrl);
return new Promise((resolve, reject) => {
uni.request({
url: baseUrl + "/user/updateuser",
method: "POST",
header: {
openId: _openid.value,
sessionKey: _sessionKey.value,
},
data: {
avatar: avatar.value,
},
timeout: 3000,
success: (res) => {
if (res.statusCode !== successCode) {
reject(res.errMsg);
}
resolve(res);
},
fail: (err) => {
reject(err);
},
});
});
};
return {
@ -95,5 +149,3 @@ const useUserStore = defineStore("user", () => {
_update_user_avatar,
};
});
export { useUserStore };

@ -1 +1 @@
export const baseUrl = "http://101.42.154.98:3000";
export const baseUrl = "http://localhost:3000/api/v1";

@ -1 +0,0 @@
export const baseUrl = "http://localhost:3000/api/v1";

@ -1,5 +1,7 @@
import { baseUrl } from "../api";
const TIME_OUT = 10000;
export const uploadImg = (filePath) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
@ -15,3 +17,73 @@ export const uploadImg = (filePath) => {
});
});
};
/**
* @param {string} type - 图片类型
* @param {string} openId - 用户openId
* @param {string} sessionKey - 用户sessionKey
* @param {string} pic_url - 图片url
*
* @returns {Promise} - 返回一个Promise对象
*/
export const uploadTypeImg = ({ type, openId, sessionKey, pic_url }) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + "/upload/img",
filePath: pic_url,
name: "img",
header: {
openId: openId,
sessionKey: sessionKey,
},
formData: {
pic_type: type,
},
timeout: TIME_OUT,
success: (res) => {
resolve(res);
},
fail: (err) => {
reject(err);
},
});
});
};
/**
* @param {string} openId - 用户openId
* @param {string} sessionKey - 用户sessionKey
* @param {Object} post_data - 发布的数据
*
* @returns {Promise} - 返回一个Promise对象
*/
export const add_post = ({ openId, sessionKey, post_data }) => {
return new Promise((resolve, reject) => {
uni.request({
url: baseUrl + "/post/add/commonshare",
method: "POST",
header: {
openId: _openid.value,
sessionKey: _sessionKey.value,
},
data: {
pic_list: post_data.pic_list,
common_share_title: post_data.common_share_title,
common_share_content: post_data.common_share_content,
nickname: post_data.nickname,
avatar: post_data.avatar,
like: post_data.like,
},
timeout: 3000,
success: (res) => {
if (res.code == 400) {
reject(res.errMsg);
}
resolve(res);
},
fail: (err) => {
reject(err);
},
});
});
};

Loading…
Cancel
Save