|  | @@ -1,10 +1,10 @@
 | 
	
		
			
				|  |  |  // CloudObject.ts
 | 
	
		
			
				|  |  |  export class CloudObject {
 | 
	
		
			
				|  |  | -    id: string | null = null; // 编号
 | 
	
		
			
				|  |  | -    className: string; // 名称
 | 
	
		
			
				|  |  | +    className: string;
 | 
	
		
			
				|  |  | +    id: string | null = null;
 | 
	
		
			
				|  |  |      createdAt:any;
 | 
	
		
			
				|  |  |      updatedAt:any;
 | 
	
		
			
				|  |  | -    data: Record<string, any> = {}; // 属性、内容
 | 
	
		
			
				|  |  | +    data: Record<string, any> = {};
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      constructor(className: string) {
 | 
	
		
			
				|  |  |          this.className = className;
 | 
	
	
		
			
				|  | @@ -29,7 +29,7 @@ export class CloudObject {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async save() {
 | 
	
		
			
				|  |  |          let method = "POST";
 | 
	
		
			
				|  |  | -        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
 | 
	
		
			
				|  |  | +        let url = `https://dev.fmode.cn/parse/classes/${this.className}`;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 更新
 | 
	
		
			
				|  |  |          if (this.id) {
 | 
	
	
		
			
				|  | @@ -61,7 +61,7 @@ export class CloudObject {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async destroy() {
 | 
	
		
			
				|  |  |          if (!this.id) return;
 | 
	
		
			
				|  |  | -        const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
 | 
	
		
			
				|  |  | +        const response = await fetch(`https://dev.fmode.cn/parse/classes/${this.className}/${this.id}`, {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
		
			
				|  |  |                  "x-parse-application-id": "dev"
 | 
	
		
			
				|  |  |              },
 | 
	
	
		
			
				|  | @@ -88,7 +88,6 @@ export class CloudQuery {
 | 
	
		
			
				|  |  |          this.className = className;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    // 作用是将查询参数转换为对象
 | 
	
		
			
				|  |  |      include(...fileds:string[]) {
 | 
	
		
			
				|  |  |          this.queryParams["include"] = fileds;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -113,11 +112,12 @@ export class CloudQuery {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      equalTo(key: string, value: any) {
 | 
	
		
			
				|  |  | +        if (!this.queryParams["where"]) this.queryParams["where"] = {};
 | 
	
		
			
				|  |  |          this.queryParams["where"][key] = value;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async get(id: string) {
 | 
	
		
			
				|  |  | -        const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
 | 
	
		
			
				|  |  | +        const url = `https://dev.fmode.cn/parse/classes/${this.className}/${id}?`;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          const response = await fetch(url, {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
	
		
			
				|  | @@ -131,34 +131,31 @@ export class CloudQuery {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          const json = await response?.json();
 | 
	
		
			
				|  |  | -        // return json || {};
 | 
	
		
			
				|  |  | -        const exists = json?.results?.[0] || null;
 | 
	
		
			
				|  |  | -        if (exists) {
 | 
	
		
			
				|  |  | -            let existsObject = this.dataToObj(exists)
 | 
	
		
			
				|  |  | +        if (json) {
 | 
	
		
			
				|  |  | +            let existsObject = this.dataToObj(json)
 | 
	
		
			
				|  |  |              return existsObject;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return null
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async find() {
 | 
	
		
			
				|  |  | -        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
 | 
	
		
			
				|  |  | +    async find():Promise<Array<CloudObject>> {
 | 
	
		
			
				|  |  | +        let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          let queryStr = ``
 | 
	
		
			
				|  |  |          Object.keys(this.queryParams).forEach(key=>{
 | 
	
		
			
				|  |  | -            let paramStr = JSON.stringify(this.queryParams[key]); // 作用是将对象转换为JSON字符串
 | 
	
		
			
				|  |  | +            let paramStr = JSON.stringify(this.queryParams[key]);
 | 
	
		
			
				|  |  |              if(key=="include"){
 | 
	
		
			
				|  |  |                  paramStr = this.queryParams[key]?.join(",")
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(key=="where"){
 | 
	
		
			
				|  |  | -                paramStr = JSON.stringify(this.queryParams[key]);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |              if(queryStr) {
 | 
	
		
			
				|  |  |                  url += `${key}=${paramStr}`;
 | 
	
		
			
				|  |  |              }else{
 | 
	
		
			
				|  |  |                  url += `&${key}=${paramStr}`;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          })
 | 
	
		
			
				|  |  | +        // if (Object.keys(this.queryParams["where"]).length) {
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +        // }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          const response = await fetch(url, {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
	
		
			
				|  | @@ -179,7 +176,7 @@ export class CloudQuery {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async first() {
 | 
	
		
			
				|  |  | -        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
 | 
	
		
			
				|  |  | +        let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (Object.keys(this.queryParams["where"]).length) {
 | 
	
		
			
				|  |  |              const whereStr = JSON.stringify(this.queryParams["where"]);
 | 
	
	
		
			
				|  | @@ -199,14 +196,11 @@ export class CloudQuery {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          const json = await response?.json();
 | 
	
		
			
				|  |  |          const exists = json?.results?.[0] || null;
 | 
	
		
			
				|  |  | -         if (exists) {
 | 
	
		
			
				|  |  | -             let existsObject = this.dataToObj(exists)
 | 
	
		
			
				|  |  | -             return existsObject;
 | 
	
		
			
				|  |  | -         }
 | 
	
		
			
				|  |  | -         return null
 | 
	
		
			
				|  |  | -        //let list = json?.results || []
 | 
	
		
			
				|  |  | -        //let objList = list.map((item:any)=>this.dataToObj(item))
 | 
	
		
			
				|  |  | -        //return objList || [];
 | 
	
		
			
				|  |  | +        if (exists) {
 | 
	
		
			
				|  |  | +            let existsObject = this.dataToObj(exists)
 | 
	
		
			
				|  |  | +            return existsObject;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return null
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      dataToObj(exists:any):CloudObject{
 | 
	
	
		
			
				|  | @@ -242,11 +236,25 @@ export class CloudUser extends CloudObject {
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return this;
 | 
	
		
			
				|  |  | +        // const response = await fetch(`https://dev.fmode.cn/parse/users/me`, {
 | 
	
		
			
				|  |  | +        //     headers: {
 | 
	
		
			
				|  |  | +        //         "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  | +        //         "x-parse-session-token": this.sessionToken // 使用sessionToken进行身份验证
 | 
	
		
			
				|  |  | +        //     },
 | 
	
		
			
				|  |  | +        //     method: "GET"
 | 
	
		
			
				|  |  | +        // });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // const result = await response?.json();
 | 
	
		
			
				|  |  | +        // if (result?.error) {
 | 
	
		
			
				|  |  | +        //     console.error(result?.error);
 | 
	
		
			
				|  |  | +        //     return null;
 | 
	
		
			
				|  |  | +        // }
 | 
	
		
			
				|  |  | +        // return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /** 登录 */
 | 
	
		
			
				|  |  |      async login(username: string, password: string):Promise<CloudUser|null> {
 | 
	
		
			
				|  |  | -        const response = await fetch(`http://dev.fmode.cn:1337/parse/login`, {
 | 
	
		
			
				|  |  | +        const response = await fetch(`https://dev.fmode.cn/parse/login`, {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
		
			
				|  |  |                  "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  |                  "Content-Type": "application/json"
 | 
	
	
		
			
				|  | @@ -255,10 +263,9 @@ export class CloudUser extends CloudObject {
 | 
	
		
			
				|  |  |              method: "POST"
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        const result = await response.json();
 | 
	
		
			
				|  |  | -        console.log("响应状态:", response.status, "响应数据:", result); // 打印响应状态和数据
 | 
	
		
			
				|  |  | -        if (result?.error||response.status !== 200) {//检查响应状态
 | 
	
		
			
				|  |  | -            console.error(result?.error|| '登录请求失败');
 | 
	
		
			
				|  |  | +        const result = await response?.json();
 | 
	
		
			
				|  |  | +        if (result?.error) {
 | 
	
		
			
				|  |  | +            console.error(result?.error);
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
	
		
			
				|  | @@ -272,15 +279,52 @@ export class CloudUser extends CloudObject {
 | 
	
		
			
				|  |  |          return this;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /** 登出 */
 | 
	
		
			
				|  |  | +    async logout() {
 | 
	
		
			
				|  |  | +        if (!this.sessionToken) {
 | 
	
		
			
				|  |  | +            console.error("用户未登录");
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        const response = await fetch(`https://dev.fmode.cn/parse/logout`, {
 | 
	
		
			
				|  |  | +            headers: {
 | 
	
		
			
				|  |  | +                "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  | +                "x-parse-session-token": this.sessionToken
 | 
	
		
			
				|  |  | +            },
 | 
	
		
			
				|  |  | +            method: "POST"
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        let result = await response?.json();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (result?.error) {
 | 
	
		
			
				|  |  | +            console.error(result?.error);
 | 
	
		
			
				|  |  | +            if(result?.error=="Invalid session token"){
 | 
	
		
			
				|  |  | +                this.clearUserCache()
 | 
	
		
			
				|  |  | +                return true;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        this.clearUserCache()
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    clearUserCache(){
 | 
	
		
			
				|  |  | +        // 清除用户信息
 | 
	
		
			
				|  |  | +        localStorage.removeItem("NCloud/dev/User")
 | 
	
		
			
				|  |  | +        this.id = null;
 | 
	
		
			
				|  |  | +        this.sessionToken = null;
 | 
	
		
			
				|  |  | +        this.data = {};
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /** 注册 */
 | 
	
		
			
				|  |  |      async signUp(username: string, password: string, additionalData: Record<string, any> = {}) {
 | 
	
		
			
				|  |  |          const userData = {
 | 
	
		
			
				|  |  |              username,
 | 
	
		
			
				|  |  | -            password,   
 | 
	
		
			
				|  |  | +            password,
 | 
	
		
			
				|  |  |              ...additionalData // 合并额外的用户数据
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        const response = await fetch(`http://dev.fmode.cn:1337/parse/users`, {
 | 
	
		
			
				|  |  | +        const response = await fetch(`https://dev.fmode.cn/parse/users`, {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
		
			
				|  |  |                  "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  |                  "Content-Type": "application/json"
 | 
	
	
		
			
				|  | @@ -296,45 +340,18 @@ export class CloudUser extends CloudObject {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 设置用户信息
 | 
	
		
			
				|  |  | +        // 缓存用户信息
 | 
	
		
			
				|  |  | +        console.log(result)
 | 
	
		
			
				|  |  | +        localStorage.setItem("NCloud/dev/User",JSON.stringify(result))
 | 
	
		
			
				|  |  |          this.id = result?.objectId;
 | 
	
		
			
				|  |  |          this.sessionToken = result?.sessionToken;
 | 
	
		
			
				|  |  |          this.data = result; // 保存用户数据
 | 
	
		
			
				|  |  |          return this;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    /** 登出 */
 | 
	
		
			
				|  |  | -    async logout() {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (!this.sessionToken) {
 | 
	
		
			
				|  |  | -            console.error("用户未登录");
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
 | 
	
		
			
				|  |  | -            headers: {
 | 
	
		
			
				|  |  | -                "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  | -                "x-parse-session-token": this.sessionToken
 | 
	
		
			
				|  |  | -            },
 | 
	
		
			
				|  |  | -            method: "POST"
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        const result = await response?.json();
 | 
	
		
			
				|  |  | -        if (result?.error) {
 | 
	
		
			
				|  |  | -            console.error(result?.error);
 | 
	
		
			
				|  |  | -            return false;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 清除用户信息
 | 
	
		
			
				|  |  | -        localStorage.removeItem("NCloud/dev/User")
 | 
	
		
			
				|  |  | -        this.id = null;
 | 
	
		
			
				|  |  | -        this.sessionToken = null;
 | 
	
		
			
				|  |  | -        this.data = {};
 | 
	
		
			
				|  |  | -        return true;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      override async save() {
 | 
	
		
			
				|  |  |          let method = "POST";
 | 
	
		
			
				|  |  | -        let url = `http://dev.fmode.cn:1337/parse/users`;
 | 
	
		
			
				|  |  | +        let url = `https://dev.fmode.cn/parse/users`;
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |          // 更新用户信息
 | 
	
		
			
				|  |  |          if (this.id) {
 | 
	
	
		
			
				|  | @@ -373,53 +390,31 @@ export class CloudUser extends CloudObject {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -// CloudEvaluate.ts
 | 
	
		
			
				|  |  | -export class CloudEvaluate extends CloudObject {
 | 
	
		
			
				|  |  | -    userData: Record<string, any>;
 | 
	
		
			
				|  |  | -    currentUser: CloudUser; // 添加当前用户的引用
 | 
	
		
			
				|  |  | -    modalCtrl: any; // 假设 modalCtrl 是通过构造函数传入的
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    constructor(userData: Record<string, any>, currentUser: CloudUser,modalCtrl: any) {
 | 
	
		
			
				|  |  | -        super("_ChatEvaluate"); 
 | 
	
		
			
				|  |  | -        this.userData = userData; // 保存用户评价数据
 | 
	
		
			
				|  |  | -        this.currentUser = currentUser; // 保存当前用户
 | 
	
		
			
				|  |  | -        this.modalCtrl = modalCtrl; // 保存模态控制器
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /** 保存评价 */
 | 
	
		
			
				|  |  | -    override async save() {
 | 
	
		
			
				|  |  | -        // 确保 rating 是数字类型
 | 
	
		
			
				|  |  | -        if (this.userData['rating']) {
 | 
	
		
			
				|  |  | -            this.userData['rating'] = Number(this.userData['rating']);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        console.log('保存评价被调用'); // 调试日志
 | 
	
		
			
				|  |  | +export class CloudApi{
 | 
	
		
			
				|  |  | +    async fetch(path:string,body:any,options?:{
 | 
	
		
			
				|  |  | +        method:string
 | 
	
		
			
				|  |  | +        body:any
 | 
	
		
			
				|  |  | +    }){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // 调用后端 API 保存评价
 | 
	
		
			
				|  |  | -        const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/ChatEvaluate`, {
 | 
	
		
			
				|  |  | +        let reqOpts:any =  {
 | 
	
		
			
				|  |  |              headers: {
 | 
	
		
			
				|  |  |                  "x-parse-application-id": "dev",
 | 
	
		
			
				|  |  |                  "Content-Type": "application/json"
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  | -            body: JSON.stringify({
 | 
	
		
			
				|  |  | -                content: this.userData['content'],
 | 
	
		
			
				|  |  | -                rating: this.userData['rating'],
 | 
	
		
			
				|  |  | -                avatar: this.currentUser.data?.['avatar'], // 假设用户头像存储在 data.avatar 中
 | 
	
		
			
				|  |  | -                user: { __type: "Pointer", className: "_User", objectId: this.currentUser.id } // 添加用户指针
 | 
	
		
			
				|  |  | -            }),
 | 
	
		
			
				|  |  | -            method: "POST"
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        const result = await response.json();
 | 
	
		
			
				|  |  | -        console.log('保存结果:', result); // 输出保存结果
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (result?.error) {
 | 
	
		
			
				|  |  | -            console.error(result?.error);
 | 
	
		
			
				|  |  | -            console.error('评价保存失败');
 | 
	
		
			
				|  |  | -            return null;
 | 
	
		
			
				|  |  | +            method: options?.method || "POST",
 | 
	
		
			
				|  |  | +            mode: "cors",
 | 
	
		
			
				|  |  | +            credentials: "omit"
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        console.log('评价保存成功:', result);
 | 
	
		
			
				|  |  | -        this.modalCtrl.dismiss(result, "confirm"); // 关闭模态框并传递结果
 | 
	
		
			
				|  |  | -        return result; // 返回保存的结果
 | 
	
		
			
				|  |  | +        if(body||options?.body){
 | 
	
		
			
				|  |  | +            reqOpts.body = JSON.stringify(body || options?.body);
 | 
	
		
			
				|  |  | +            reqOpts.json = true;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        let host = `https://dev.fmode.cn`
 | 
	
		
			
				|  |  | +        // host = `http://127.0.0.1:1337`
 | 
	
		
			
				|  |  | +        let url = `${host}/api/`+path
 | 
	
		
			
				|  |  | +        console.log(url,reqOpts)
 | 
	
		
			
				|  |  | +        const response = await fetch(url,reqOpts);
 | 
	
		
			
				|  |  | +        let json = await response.json();
 | 
	
		
			
				|  |  | +        return json
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |