- 云开发nodejs云函数,如何调用本地CSS、JS文件?
以下Demo为例,demo参加了一个页面,但页面中的库都是cdn过来的。 我希望再云函数根目录新建CSS或JS,实现本地调用。或者通过云存储调用也行。 尝试调用本地文件的代码(但这样是无法实现的): <link href="cloud://wework-1c9fv.7765-wework-1c9fv-1302668058/cdn/fonts.css" rel="stylesheet" type="text/css"> <link href="\fonts.css" rel="stylesheet" type="text/css"> 完整代码: //替换 envId 为您的环境ID const ENV_ID = "XXXX" exports.main = async (event) => { // 网页JS代码 const script = ` const ENV_ID = "${ENV_ID}" class FunctionQuickStarter { constructor() { // 初始化 CloudBase this.app = cloudbase.init({ env: ENV_ID, region: "ap-shanghai" }) this.signIn() } // 匿名登录 signIn() { var auth = this.app.auth({ persistence: "local" }) if (!auth.hasLoginState()) { auth.anonymousAuthProvider().signIn() .then(() => { this.setButtonStatus(false) }) } else { this.setButtonStatus(false) } } } window.addEventListener("load", function () { window.app = new FunctionQuickStarter() }) ` // 网页HTML代码 const body = `<!DOCTYPE html> <html> <!-- WARNING! Make sure that you match all Quasar related tags to the same version! (Below it's "@2.3.3") --> <head> <!-- 问题在这里 --> <link href="cloud://wework-1c9fv.7765-wework-1c9fv-1302668058/cdn/fonts.css" rel="stylesheet" type="text/css"> <link href="\fonts.css" rel="stylesheet" type="text/css"> <link href="https://cdn.jsdelivr.net/npm/animate.css@^4.0.0/animate.min.css" rel="stylesheet" type="text/css"> <link href="https://cdn.jsdelivr.net/npm/quasar@2.3.3/dist/quasar.prod.css" rel="stylesheet" type="text/css"> </head> <body> <!-- example of injection point where you write your app template --> <div id="q-app" style="min-height: 100vh;"> <div class="q-pa-md" style="max-width: 400px"> <q-form @submit="onSubmit" @reset="onReset" class="q-gutter-md"> <q-input filled v-model="name" label="Your name *" hint="Name and surname" lazy-rules :rules="[ val => val && val.length > 0 || 'Please type something']"></q-input> <q-input filled type="number" v-model="age" label="Your age *" lazy-rules :rules="[ val => val !== null && val !== '' || 'Please type your age', val => val > 0 && val < 100 || 'Please type a real age' ]"></q-input> <q-toggle v-model="accept" label="I accept the license and terms"></q-toggle> <div> <q-btn label="Submit" type="submit" color="primary"></q-btn> <q-btn label="Reset" type="reset" color="primary" flat class="q-ml-sm"></q-btn> </div> </q-form> </div> </div> <!-- Add the following at the end of your body tag --> <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script> <script src="https://cdn.jsdelivr.net/npm/quasar@2.3.3/dist/quasar.umd.prod.js"></script> <script src="https://cdn.jsdelivr.net/npm/quasar@2.3.3/dist/lang/zh-CN.umd.prod.js"></script> <script> /* Example kicking off the UI. Obviously, adapt this to your specific needs. Assumes you have a <div id="q-app"></div> in your <body> above */ const { useQuasar } = Quasar const { ref } = Vue const app = Vue.createApp({ setup() { const $q = useQuasar() const name = ref(null) const age = ref(null) const accept = ref(false) return { name, age, accept, onSubmit() { if (accept.value !== true) { $q.notify({ color: 'red-5', textColor: 'white', icon: 'warning', message: 'You need to accept the license and terms first' }) } else { $q.notify({ color: 'green-4', textColor: 'white', icon: 'cloud_done', message: 'Submitted' }) } }, onReset() { name.value = null age.value = null accept.value = false } } } }) app.use(Quasar, { config: {} }) app.mount('#q-app') </script> </body> </html>` return { statusCode: 200, headers: { 'content-type': 'text/html' }, body: body } }
2021-11-23 - 微信小程序端下载云存储文件的问题?
可以成功获得res.tempFilePath,但之后没有任何反馈,也不见保存成功。 帮忙看看我的代码有什么问题,谢谢。 _downloadFile: function () { wx.cloud.downloadFile({ fileID: 'cloud://(屏蔽数据58)/cloudbase-cms/upload/2021-10-29/gp79hfu7xqgh3ijzmgiimt7a61g2060b_.xlsx' }).then(res => { console.log(res.tempFilePath) wx.saveFile({ tempFilePath: res.tempFilePath, success(res) { const savedFilePath = res.savedFilePath }, fail: err => { console.log(err) } }) }).catch(e => { console.log(e); }) }
2021-11-02 - rich-text是否可以仅显示文本不显示样式?
我希望rich-text自显示文本,不渲染样式,如何可以实现?谢谢
2021-10-29 - db.RegExp转义存在BUG?
情况是这样的,由于数据库需要查询的字段涉及到正则的特殊字符,例如(、-等。 一开始我这样查,根本查询不到内容: return await db.collection(event.collection).aggregate() .match({ equipmentName: new db.RegExp({ regexp: '茂名茂南区华侨新村宿舍I4二级(扩)', options: 'i', }) }) .group({ _id: { _id: '$_id', department1: '$equipmentName', department2: '$boxName' } }) .end(); 后来我想到应该是我未转义特殊字符,于是我这样查,但仍然是查不到内容: return await db.collection(event.collection).aggregate() .match({ equipmentName: new db.RegExp({ regexp: '茂名茂南区华侨新村宿舍I4二级\(扩\)', options: 'i', }) }) .group({ _id: { _id: '$_id', department1: '$equipmentName', department2: '$boxName' } }) .end(); 后来我尝试这样,竟然能查询到内容: return await db.collection(event.collection).aggregate() .match({ equipmentName: /茂名茂南区华侨新村宿舍I4二级\(扩\)/i }) .group({ _id: { _id: '$_id', department1: '$equipmentName', department2: '$boxName' } }) .end(); 是不是证明db.RegExp转义存在BUG? 另外,希望官方简单说明一下关于RegExp查询的转义,官方建议的写法是怎样的?谢谢
2021-10-23 - 聚合aggregate的match是否可以使用Regexp条件?
需求,聚合阶段模糊查询。 看了一个老帖:聚合阶段,无法进行模糊匹配吗?? 邓坤力 的回答 - 微信开放社区 https://developers.weixin.qq.com/community/develop/doc/0004a6e5574f10d5797915c845b000?jumpto=comment&commentid=000ca4f464cb2030b0890178251c 但我写的代码不行,麻烦帮忙看看哪里写错了?感谢。 1、用等值条件,能正常获得数据: return await db.collection(event.collection).aggregate() .match(_.or([ { equipmentName: '茂名茂南区华侨新村宿舍I4二级(扩)(H)-POS001-1:8(13-12)' }, { boxName: '茂名茂南区华侨新村宿舍I4二级(扩)(H)-POS001-1:8(13-12)' } ])) .group({ _id: { _id: '$_id', department1: '$equipmentName', department2: '$boxName' } }) .end(); 2、用Regexp条件,不能获得数据: return await db.collection(event.collection).aggregate() .match(_.or([ { equipmentName: db.RegExp({ regexp: '茂名茂南区华侨新村宿舍I4二级(扩)(H)-POS001-1:8(13-12)', options: 'i', }) }, { boxName: db.RegExp({ regexp: '茂名茂南区华侨新村宿舍I4二级(扩)(H)-POS001-1:8(13-12)', options: 'i', }) } ])) .group({ _id: { _id: '$_id', department1: '$equipmentName', department2: '$boxName' } }) .end();
2021-10-23 - 聚合阶段match如何过滤日期?
聚合阶段match如何过滤日期?文档说match条件语法同where,但测试过了,按照如下语法不能正确过滤,求指教,谢谢。 数据库的month字段格式为date对象。 match={ class: '薪酬', month: _.lt(new Date(that.data.startDay)) }
2021-10-21 - 关于 模板 template 多个data的使用 ?
第一次用template,不是很熟。 以下是一个翻页的template,其中涉及多个data,包括listEquipment、getEquipmentData、callingCloud。 <template name="turn-pages-equipment"> <view class="padding-m flex-center solid-top"> <view class="flex align-center justify-between flex-1"> <view class="{{listEquipment && (getEquipmentData.skip + 1) > 1 && !callingCloud?'':'is-disabled'}}" data-target="-1" bindtap="bindEquipmentTurnPages"> <text class="bbIcon-left"></text> <text>上页</text> </view> <view class="text-gray"> <text>{{getEquipmentData.total}}条</text> </view> <view class="text-gray"> <text>{{getEquipmentData.pageCount}} / {{getEquipmentData.skip + 1}}页</text> </view> <view class="{{listEquipment && getEquipmentData.pageCount > (getEquipmentData.skip + 1) && !callingCloud?'':'is-disabled'}}" data-target="1" bindtap="bindEquipmentTurnPages"> <text>下页</text> <text class="bbIcon-right"></text> </view> </view> </view> </template> 这种多个data的情况,我如何调用?或者有什么可以改进的写法?请各位指教,谢谢。 <template is="turn-pages-equipment" data="{{getEquipmentData}}"></template>
2021-10-19 - web前端flex的问题?
我希望构建一个页面(main),分为标题(header)和内容(content)两大部分。 标题固定不变的,内容是滚动的(scroll-view)。 首先通过main通过height: 100vh定义了页面高度,然后content通过flex:1定义了自动填充高度。 但content会被内容撑高,scroll-view不能滚动,导致变成了整个页面的滚动。 也尝试过在scroll-view外面套一个view来flex:1,但仍然无效。 求各位指教,谢谢。 <view class="main"> <view class="header"> 标题 </view> <view class="content"> <scroll-view scroll-y> <view>内容1</view> <view>内容2</view> <view>内容3</view> <view>内容4</view> <view>内容5</view> <view>内容6</view> <view>内容7</view> <view>内容8</view> <view>内容9</view> <view>内容10</view> </scroll-view> </view> </view> .main { height: 100vh; display: flex; flex-direction: column; } .header { padding: 50px; background-color: bisque; } .content { /* flex: 1; */ background-color: chartreuse; } .content view { border: 1px sienna solid; height: 100px; }
2021-10-17 - 前端向后端传递db.command条件的问题?
出于权限、数据查询条数限制、数据库安全等考虑,寡人一直都只通过云函数对数据库进行增查改操作。也就是在前端把data、where等条件传到云函数完成操作。 问题来了,前端到后端的无法直接传递db.command这种数据。 一开始我想到一个折衷的方法,前端这样写: val1: 'command="thisIsOpenid"' val2: 'command=db.serverDate()' val3: 'command=new Date(new Date("1984-09-03 18:19:08").setHours(firstDate.getHours() - 8))' 后端再递归遍历过来(这种情况下Key与val的层次比较正常): // 递归遍历并替换指定值 async function funForIn(data, OPENID) { for (let i in data) { if (typeof data[i] == 'object') { funForIn(data[i]) } else { // 替换OPENID if (String(data[i]).includes('thisIsOpenid')) { data[i] = data[i].replace(/thisIsOpenid/g, OPENID) } if (String(data[i]).slice(0, 8) == 'command=') { // 查询指令 data[i] = eval(data[i].slice(8)) } else if (String(data[i]).slice(0, 7) == 'regExp=') { // 正则Get data[i] = db.RegExp({ regexp: String(data[i].slice(7)), options: 'i', }) } } } } 基本上可以解决大部分的需求,但问题来了,对于Key与val层次另类的,类似这种,就无能为力了。 db.collection('todo').where(_.or([ { progress: _.gt(80) }, { done: true } ])) 所以,为了实现前端向后端传db.command条件,各位大佬有什么好的办法?谢谢。
2021-10-16 - 小程序如何引用云存储中的图片?
如题,如果要在小程序中引用云存储的图片,正确方法是怎样?直接src下载地址? 还是可以通过“存储位置”或ETag等来引用?
2021-10-05