Skip to content

Commit a402d02

Browse files
committed
feat: idframe
1 parent 99c52e7 commit a402d02

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/*.dist.js
2+
.nuxt
3+
.vscode

idframe/appbar.dist.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

idframe/appbar.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{
1+
/* eslint-disable unicorn/prefer-includes */
2+
;(() => {
23
const data = __data__ // eslint-disable-line no-undef
34
const defaultItems = [ 'nickname', 'myaccount', 'divider', 'kredit', 'recharge', 'divider', 'logout' ]
45
const shortItems = {
@@ -133,7 +134,7 @@
133134
* @param {(string|object)[]} items items to be displayed.
134135
*/
135136
updateItems (items) {
136-
if (!Array.isArray(items)) throw new TypeError('Items not an array')
137+
if (!items || items.length === undefined) throw new TypeError('Items not an array')
137138
const oldItems = this.items
138139
this.items = items
139140
try {
@@ -203,7 +204,7 @@
203204
let has = !used[i][0]
204205
if (!('mdc' in window.idFrame) || !window.idFrame.mdc.style) {
205206
for (let j = 0; j < document.styleSheets.length; j++) {
206-
if ((document.styleSheets[j].href || '').includes(i)) has = true
207+
if ((document.styleSheets[j].href || '').indexOf(i) > -1) has = true
207208
}
208209
if (!has) {
209210
const el = document.createElement('link')
@@ -215,7 +216,7 @@
215216
if (!('mdc' in window.idFrame) || !window.idFrame.mdc.script) {
216217
has = !used[i][1]
217218
for (let j = 0; j < document.scripts.length; j++) {
218-
if ((document.scripts[j].src || '').includes(i)) has = true
219+
if ((document.scripts[j].src || '').indexOf(i) > -1) has = true
219220
}
220221
if (!has) {
221222
const el = document.createElement('script')
@@ -224,4 +225,4 @@
224225
}
225226
}
226227
}
227-
}
228+
})()

idframe/serve.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const { readFileSync } = require('fs')
22
const path = require('path')
3-
const script = readFileSync(path.resolve(__dirname, 'appbar.js')).toString()
3+
const script = readFileSync(path.resolve(__dirname, 'appbar.dist.js')).toString()
44

55
exports.applyIdframeRoutes = router => router.get('/api/idframe', ctx => {
66
const info = ctx.getUserInformation()
77
const data = info ? { ...info, loggedIn: true } : { loggedIn: false }
88
const str = JSON.stringify(data).replace(/\//g, '\\u002F')
99
ctx.set('Content-Type', 'application/javascript')
10+
ctx.set('Cache-Control', 'no-cache')
1011
ctx.body = script.replace('__data__', str)
1112
})

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
"scripts": {
88
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
99
"build": "cross-env NODE_ENV=production nuxt build",
10+
"build:idframe": "babel idframe/appbar.js | uglifyjs -mc > idframe/appbar.dist.js",
1011
"start": "cross-env NODE_ENV=production node server/index.js",
1112
"generate": "nuxt generate",
12-
"lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
13+
"lint": "eslint --ext .js,.vue --ignore-path .eslintignore ."
14+
},
15+
"babel": {
16+
"presets": [ "@babel/env" ]
1317
},
1418
"dependencies": {
1519
"@keeer/libphonenumber": "^1.7.44-keeer1",

scripts/deploy-to-oss.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const consola = require('consola')
1616
const store = new OSS(cfg)
1717
const distDir = '.nuxt/dist/client'
1818
for (const file of await readdir(distDir)) {
19+
if (file.includes('idframe')) continue
1920
await store.put(path.join(process.env.ALI_OSS_ASSETS_PREFIX || '', file), path.join(distDir, file), {
2021
headers: { 'Cache-Control': 'public, max-age=31536000' },
2122
})

0 commit comments

Comments
 (0)