Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信小程序,清空1日,20日,30日数据报错 #55

Open
xiejunping opened this issue May 12, 2021 · 1 comment
Open

微信小程序,清空1日,20日,30日数据报错 #55

xiejunping opened this issue May 12, 2021 · 1 comment

Comments

@xiejunping
Copy link

1、 代码未改动时,提示 appID 不能为空,
看代码是在 setting.html 中没有传入 appId,

                removeWebDB1Data(){
			popup.confirm({title:'确定清空1日之前所有数据吗?',yes:()=>{
				util.ajax({
					url:`${config.baseApi}api/v1/remove/deleteDb1WebData`,
					data: {
						type: 'wx',
						appId: this.appId
					},
					success:data=>{
						popup.alert({title:'操作成功!'})
					}
				})
			}})
		},
		removeWebDB2Data(number){
			popup.confirm({
				title: `确定清空${number}日之前所有数据吗?`, yes: () => {
					util.ajax({
						url: `${config.baseApi}api/v1/remove/deleteDb2WebData`,
						data:{
							number: number,
							type: 'wx',
							appId: this.appId
						},
						success: data => {
							popup.alert({ title: '操作成功!' })
						}
					})
				}
			})
		},

上面是贴了改后的,看了网页项目的代码改的

2、 这样改了又是报错,报remove 为 undefind 。看了代码后,原因是分项目分表后,表名是要appId的,这里明显没有传,但是直接(appId)是不可以了,因为model不存在,所以改后代码如下:

async deleteDb2WebData(appId, number, type = 'web') {
        number = number * 1;
        const interval = parser.parseExpression(this.app.config.pvuvip_task_day_time);
        const endTime = new Date(new Date(interval.prev().toString()).getTime() - number * 86400000);
        const query = { create_time: { $lt: endTime } };
        let result = null;

        if (type === 'web') {
            // Ajax
            const remove1 = Promise.resolve(this.app.models.WebAjaxs(appId).remove(query).exec());
            // Pages
            const remove2 = Promise.resolve(this.app.models.WebPages(appId).remove(query).exec());
            // Environment
            const remove3 = Promise.resolve(this.app.models.WebEnvironment(appId).remove(query).exec());
            // Errors
            const remove4 = Promise.resolve(this.app.models.WebErrors(appId).remove(query).exec());
            // Resource
            const remove5 = Promise.resolve(this.app.models.WebResource(appId).remove(query).exec());
            result = await Promise.all([ remove1, remove2, remove3, remove4, remove5 ]);
        } else if (type === 'wx') {
            // Ajax
            const remove1 = Promise.resolve(this.app.models.WxAjaxs(appId).remove(query).exec());
            // Pages
            const remove2 = Promise.resolve(this.app.models.WxPages(appId).remove(query).exec());
            // Errors
            const remove3 = Promise.resolve(this.app.models.WxErrors(appId).remove(query).exec());
            result = await Promise.all([ remove1, remove2, remove3 ]);
        }
        return result;
}

上面代码的路径是 service/remove.js

已上改完就可以了,没有提pull request,看作者也不怎么更新,但是人加能开源就不错了,自己能动手的就不要键盘侠

good night!

@wangweianger
Copy link
Owner

这边我会抽时间看看,修复完成会回复你

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants