yuanyiming 1 سال پیش
والد
کامیت
3fb29cfb0b
6فایلهای تغییر یافته به همراه90 افزوده شده و 23 حذف شده
  1. 3 3
      App.vue
  2. 2 1
      api/request.js
  3. 10 6
      components/teaching-case/teaching-case.vue
  4. 59 0
      limits.md
  5. 15 12
      pages/login/login.vue
  6. 1 1
      pages/mine/mine.vue

+ 3 - 3
App.vue

@@ -7,11 +7,11 @@
 			wx.login({
 				success({code}) {
 					uni.request({
-						url:'http://localhost:7003/api/pbl/weChatCode',
+						url:'https://teacherapi.cocorobo.cn/api/pbl/weChatCode',
 						method:'GET',
 						data:{codes:code}
-					}).then(res=>{
-						// console.log(res);
+					}).then(res=>{ 
+						console.log(res);
 						uni.setStorageSync('oId',res.data)
 					})
 				}

+ 2 - 1
api/request.js

@@ -7,7 +7,8 @@ const request = (url = '', method = 'GET', data = {}, header = {   //这里这
 	return new Promise((resolve, reject) => {
 		// console.log(header);
 		uni.request({
-			url: 'http://localhost:7003/api/pbl' + url, //接口地址:前缀+方法中传入的地址
+			url: 'https://teacherapi.cocorobo.cn/api/pbl' + url, //接口地址:前缀+方法中传入的地址
+			// url: 'http://localhost:7333/api/pbl' + url, //接口地址:前缀+方法中传入的地址
 			method: method, //请求方法
 			data: data, //传递参数
 			header: header, //自定义头部,和后端商同后编写

+ 10 - 6
components/teaching-case/teaching-case.vue

@@ -125,20 +125,24 @@
 		},
 		methods: {
 			gotoTeDetail(e) {
-				console.log(e.currentTarget.dataset['index'], 123);
+				// console.log(e.currentTarget.dataset['index'], 123);
 				let edata = e.currentTarget.dataset['index']
 
 				const value = this.$store.state.user.openid;
 
 				const urls = [
-					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1181",
-					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1183",
-					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1210",
-					"https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1234",
+					// "https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1181",
+					// "https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1183",
+					// "https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1210",
+					// "https://szptxnjys.yuketang.cn/pro/portal/announcementdetail/1234",
+					"https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00351166273N",
+					"https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00330324841N",
+					"https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00231455802N",
+					"https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00406339964N",
 				];
 				console.log(value);
 				if (value == '') {
-					console.log(111);
+					// console.log(111);
 					uni.navigateTo({
 						url: "/pages/login/login",
 					});

+ 59 - 0
limits.md

@@ -0,0 +1,59 @@
+const multer = require('koa-multer');
+const fs = require('fs');
+const path = require('path');
+
+// 设置文件存储位置和上传大小限制
+let storage = multer.diskStorage({
+  destination: function (req, file, cb) {
+    let date = new Date();
+    let year = date.getFullYear();
+    let month = date.getMonth() + 1;
+    let day = date.getDate();
+    let dir = "./public/uploads/" + year + month + day;
+
+    if (!fs.existsSync(dir)) {
+      fs.mkdirSync(dir, {
+        recursive: true,
+      });
+    }
+    cb(null, dir);
+  },
+  filename: function (req, file, cb) {
+    let fileName =
+      file.fieldname + "-" + Date.now() + path.extname(file.originalname);
+    cb(null, fileName);
+  },
+});
+
+const upload = multer({
+  storage: storage,
+  limits: {
+    fileSize: 5 * 1024 * 1024, // 5MB的文件大小限制
+  },
+});
+
+// 上传图片接口
+router.post("/img", upload.single("file"), async (ctx) => {
+  let path = ctx.req.file.path;
+  path = ctx.origin + "" + path.replace("public", "");
+  path = path.replace(/\\/g, "/");
+  console.log(path);
+
+  ctx.body = path;
+});
+
+// 错误处理程序
+app.use((ctx, next) => {
+  return next().catch((err) => {
+    if (err.name === "MulterError") {
+      ctx.status = 400; // 设置响应状态码为400,表示请求错误
+      ctx.body = "文件大小超过限制"; // 返回给客户端的提示信息
+    } else {
+      throw err;
+    }
+  });
+});
+
+app.listen(3000, () => {
+  console.log('Server is running on port 3000');
+});

+ 15 - 12
pages/login/login.vue

@@ -102,21 +102,30 @@
 			gotoIndex() {
 				
 				let oId=uni.getStorageSync('oId')
+				console.log('gotoIndex:',oId);
 				let all=[]
 				// 检查是否注册过
 				this.$request('/selectUser', 'POST', {
 					oId:oId,
 				}).then(res => {
-					console.log(res[0]);
-					this.$store.dispatch('asyncUpdateUser',res[0][0])
-					if (!res[0]) {
+					console.log('selectUser',res[0]);
+					
+				 	console.log(res[0]==false);
+				
+					if(res[0]==false) {
+						console.log('还未注册过,开始注册');
 						this.$request('/login', 'POST', {
-							openid:9999,
+							openid:oId,
 							Nme:'默认名称'
 						}).then(res => {
-							console.log(res);
+							console.log(res,11111);
 							uni.setStorageSync('token',res.token)
+							// 注册过后重新登录
+							this.gotoIndex()
 						})
+					}else{
+						console.log('登录过了',res[0]);
+						this.$store.dispatch('asyncUpdateUser',res[0][0])
 					}
 				})
 				uni.switchTab({
@@ -124,13 +133,7 @@
 				})
 				
 			},
-			kk(){
-					this.$request('/a', 'POST', {
-						oId:2222,
-					}).then(res => {
-						console.log(res);
-					})
-			},
+			
 			goto() {
 				uni.navigateTo({
 					url: "/pages/login_two/login_two"

+ 1 - 1
pages/mine/mine.vue

@@ -139,7 +139,7 @@ export default {
 		}
 	},
 	onShow() {
-		console.log(this.$store.state.user.openid);
+		console.log(this.$store.state.user.openid,11111);
 		this.isManage =this.$store.state.user.openid;
 		console.log(this.isManage=="");
 	}