Skip to content

Commit

Permalink
Chore: (release) 1.2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Maorey committed May 13, 2020
1 parent 957f9fe commit 2c25285
Show file tree
Hide file tree
Showing 10 changed files with 501 additions and 376 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ compile

.yarn
.yarnrc
yarn.lock
.pnp.js

# 测试
Expand Down Expand Up @@ -34,3 +33,4 @@ report.*.json

# 其他忽略文件(夹)
~*
*~
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 更新日志

## v 1.2.16

- 文件/图片数据仓库, 下载任务增加禁用缓存选项

## v 1.2.15

- 指定入口
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-tpl",
"version": "1.2.15",
"version": "1.2.16",
"private": false,
"description": "vue + vuex + vue router + TypeScript(支持 JavaScript) 模板",
"author": "毛瑞 <[email protected]>",
Expand Down Expand Up @@ -32,11 +32,11 @@
"vue-i18n": "^8.17.4",
"vue-property-decorator": "^8.4.2",
"vue-router": "^3.1.6",
"vuex": "^3.3.0",
"vuex": "^3.4.0",
"vuex-class": "^0.3.2",
"vuex-module-decorators": "^0.17.0",
"zdog": "^1.1.2",
"zrender": "^4.3.0"
"zrender": "^4.3.1"
},
"devDependencies": {
"@babel/plugin-proposal-export-default-from": "^7.8.3",
Expand All @@ -47,22 +47,22 @@
"@types/d3": "^5.7.2",
"@types/echarts": "^4.6.0",
"@types/jest": "^25.2.1",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"@vue/cli-plugin-babel": "~4.3.1",
"@vue/cli-plugin-e2e-cypress": "~4.3.1",
"@vue/cli-plugin-eslint": "~4.3.1",
"@vue/cli-plugin-pwa": "~4.3.1",
"@vue/cli-plugin-router": "~4.3.1",
"@vue/cli-plugin-typescript": "~4.3.1",
"@vue/cli-plugin-unit-jest": "~4.3.1",
"@vue/cli-plugin-vuex": "~4.3.1",
"@vue/cli-service": "~4.3.1",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"@vue/cli-plugin-babel": "^4.3.1",
"@vue/cli-plugin-e2e-cypress": "^4.3.1",
"@vue/cli-plugin-eslint": "^4.3.1",
"@vue/cli-plugin-pwa": "^4.3.1",
"@vue/cli-plugin-router": "^4.3.1",
"@vue/cli-plugin-typescript": "^4.3.1",
"@vue/cli-plugin-unit-jest": "^4.3.1",
"@vue/cli-plugin-vuex": "^4.3.1",
"@vue/cli-service": "^4.3.1",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/eslint-config-typescript": "^5.0.2",
"@vue/test-utils": "^1.0.2",
"alternate-css-extract-plugin": "^0.9.4",
"compression-webpack-plugin": "^3.1.0",
"compression-webpack-plugin": "^4.0.0",
"eslint": "^7.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -81,7 +81,7 @@
"stylelint": "^13.3.3",
"stylelint-config-scss-maorey": "^1.1.1",
"stylelint-webpack-plugin": "^2.0.0",
"typescript": "~3.8.3",
"typescript": "^3.9.2",
"unicode-match-property-ecmascript": "^1.0.4",
"unicode-match-property-value-ecmascript": "^1.2.0",
"vue-template-compiler": "^2.6.11",
Expand Down
10 changes: 5 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<meta charset="utf-8" />
<title>index - <%= process.env.APP_NAME %></title>

<!-- 功能性元数据 -->
<!-- 优先使用 edge 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 优先webkit内核(360等浏览器) -->
<meta name="renderer" content="webkit" />

<!-- 缓存相关(不让百度转码) -->
<meta http-equiv="Cache-Control" content="max-age=604800,no-siteapp" />
<!-- <meta http-equiv="Pragma" content="max-age=604800" />
<meta http-equiv="Expires" content="Thu, 03 Jan 2020 02:19:10 GMT" /> -->

<!-- 优先使用 edge 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 优先webkit内核(360等浏览器) -->
<meta name="renderer" content="webkit" />
<!-- 移动端网页可视区域 -->
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

Expand Down
10 changes: 5 additions & 5 deletions public/other.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<meta charset="utf-8" />
<title>other - <%= process.env.APP_NAME %></title>

<!-- 功能性元数据 -->
<!-- 优先使用 edge 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 优先webkit内核(360等浏览器) -->
<meta name="renderer" content="webkit" />

<!-- 缓存相关(不让百度转码) -->
<meta http-equiv="Cache-Control" content="max-age=604800,no-siteapp" />
<!-- <meta http-equiv="Pragma" content="max-age=604800" />
<meta http-equiv="Expires" content="Thu, 03 Jan 2020 02:19:10 GMT" /> -->

<!-- 优先使用 edge 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 优先webkit内核(360等浏览器) -->
<meta name="renderer" content="webkit" />
<!-- 移动端网页可视区域 -->
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

Expand Down
3 changes: 3 additions & 0 deletions src/components/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class extends Vue {
@Prop() readonly text?: string
/** 是否禁用 */
@Prop() readonly disabled?: boolean
/** 是否禁用缓存(比如导出文件) */
@Prop() readonly noCache?: boolean
/** 图标(默认取文件名后缀) */
@Prop() readonly icon?: string
/// [data] (attr: string = '响应式属性' // 除了 undefined) ///
Expand Down Expand Up @@ -90,6 +92,7 @@ export default class extends Vue {
url: this.href,
query: this.query,
name: this.fileName,
noCache: this.noCache,
},
callback: task => {
if (task === this.task) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class extends Vue {
@Prop() readonly src!: string
/** 查询参数 */
@Prop() readonly query?: IObject
/** 是否禁用缓存 */
@Prop() readonly noCache?: boolean
/** 同 <img alt> */
@Prop() readonly alt?: string
/** 滚动容器选择器(document.querySelector), 若设置则懒加载【不响应prop变化】 */
Expand Down Expand Up @@ -99,7 +101,7 @@ export default class extends Vue {
@Watch('query', { deep: true })
protected load() {
this.store.LOAD({
task: { url: this.src, query: this.query },
task: { url: this.src, query: this.query, noCache: this.noCache },
callback: task => {
this.task = task
},
Expand Down
57 changes: 40 additions & 17 deletions src/store/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface IParams {
name?: string
/** 文件类型 */
type?: string
/** 不缓存 比如导出文件 */
noCache?: boolean
}
/** 任务 */
export interface ITask extends IParams {
Expand Down Expand Up @@ -161,6 +163,18 @@ function removeCache(tasks: ITask[], task: ITask | string) {

return 0
}
function insertRemoveableTask(removeableTasks: ITask[], task: ITask) {
if (task.noCache) {
for (let i = 0, len = removeableTasks.length; i < len; i++) {
if (!removeableTasks[i].noCache) {
removeableTasks.splice(i, 0, task)
return
}
}
} else {
removeableTasks.push(task)
}
}

/// for 互相调用 ///
function next(this: IFile, updateProgressOnly?: boolean) {
Expand All @@ -184,7 +198,9 @@ function next(this: IFile, updateProgressOnly?: boolean) {
}
}

shouldRemove && state === STATE.saved && tasksRemoveable.push(temp)
shouldRemove &&
state === STATE.saved &&
insertRemoveableTask(tasksRemoveable, temp)
}

if ((temp = tasksRemoveable.length)) {
Expand Down Expand Up @@ -215,14 +231,16 @@ function ADD_TASK(
const tasks = this.tasks
let item
let key
for (item of tasks) {
if (task.url === item.url && isEqual(task.query, item.query)) {
if (task.name === item.name && task.type === item.type) {
return item
}
if (!task.noCache) {
for (item of tasks) {
if (task.url === item.url && isEqual(task.query, item.query)) {
if (task.name === item.name && task.type === item.type) {
return item
}

key = item.key
break
key = item.key
break
}
}
}

Expand Down Expand Up @@ -402,12 +420,12 @@ export default class File extends VuexModule implements IFile {
const tasks = this.tasks

const max = config.max
let loading = max - this.loading

const RAM = config.RAM

const remove = tasks.length - config.size
const shouldRemove = remove > 0 || this.RAM > RAM

let loading = max - this.loading
if (loading || shouldRemove) {
const shouldPause = loading < 0
const tasksRemoveable: ITask[] = []
Expand All @@ -429,10 +447,11 @@ export default class File extends VuexModule implements IFile {
}
}

shouldRemove && state === STATE.saved && tasksRemoveable.push(task)
shouldRemove &&
state === STATE.saved &&
insertRemoveableTask(tasksRemoveable, task)
}

// 不用pop
for (
count = 0, state = tasksRemoveable.length;
count < state && (count < remove || this.RAM > RAM);
Expand Down Expand Up @@ -644,11 +663,15 @@ export default class File extends VuexModule implements IFile {
// eslint-disable-next-line no-fallthrough
case STATE.saved:
save(cache.f as IFileInfo)
clearTimeout(cache.t)
;(alive = this.config.alive) &&
(cache.t = setTimeout(() => {
REMOVE_TASK.call(this, { task })
}, alive))
if (task.noCache) {
REMOVE_TASK.call(this, { task })
} else {
clearTimeout(cache.t)
;(alive = this.config.alive) &&
(cache.t = setTimeout(() => {
REMOVE_TASK.call(this, { task })
}, alive))
}
next.call(this, this.usage <= 1)
break
}
Expand Down
60 changes: 45 additions & 15 deletions src/store/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface IParams {
url: string
/** 查询参数 */
query?: IObject
/** 不缓存 比如导出文件 */
noCache?: boolean
}
/** 任务 */
export interface ITask extends IParams {
Expand Down Expand Up @@ -96,6 +98,18 @@ function removeCache(task: ITask) {

return 0
}
function insertRemoveableTask(removeableTasks: ITask[], task: ITask) {
if (task.noCache) {
for (let i = 0, len = removeableTasks.length; i < len; i++) {
if (!removeableTasks[i].noCache) {
removeableTasks.splice(i, 0, task)
return
}
}
} else {
removeableTasks.push(task)
}
}

/// for 互相调用 ///
function next(this: Image, updateUsageOnly?: boolean) {
Expand All @@ -119,7 +133,9 @@ function next(this: Image, updateUsageOnly?: boolean) {
}
}

shouldRemove && state === STATE.success && tasksRemoveable.push(temp)
shouldRemove &&
state === STATE.success &&
insertRemoveableTask(tasksRemoveable, temp)
}

if ((temp = tasksRemoveable.length)) {
Expand Down Expand Up @@ -237,8 +253,8 @@ export default class Image extends VuexModule implements IImage {
const max = config.max
const RAM = config.RAM

let loading = max - (this.loading || 0)
const shouldRemove = this.RAM > RAM
let loading = max - (this.loading || 0)
if (loading || shouldRemove) {
const shouldPause = loading < 0

Expand All @@ -260,14 +276,17 @@ export default class Image extends VuexModule implements IImage {
}
}

shouldRemove && state === STATE.success && tasksRemoveable.push(task)
shouldRemove &&
state === STATE.success &&
insertRemoveableTask(tasksRemoveable, task)
}

// 不用pop
count = 0
state = tasksRemoveable.length
while (count++ < state && this.RAM > RAM) {
REMOVE_TASK.call(this, tasksRemoveable[state - count])
for (
count = 0, state = tasksRemoveable.length;
count < state && this.RAM > RAM;
count++
) {
REMOVE_TASK.call(this, tasksRemoveable[count])
}
}
}
Expand All @@ -279,12 +298,14 @@ export default class Image extends VuexModule implements IImage {
const tasks = this.tasks
const task = payload.task as ITask
let item
for (item of tasks) {
if (task.url === item.url && isEqual(task.query, item.query)) {
item.ref || (item.ref = 1)
SET_STATE.call(this, item, STATE.loading)
payload.callback(item)
return
if (!task.noCache) {
for (item of tasks) {
if (task.url === item.url && isEqual(task.query, item.query)) {
item.ref || (item.ref = 1)
SET_STATE.call(this, item, STATE.loading)
payload.callback(item)
return
}
}
}

Expand All @@ -300,7 +321,16 @@ export default class Image extends VuexModule implements IImage {
/** 标记不再使用指定图片 */
@Mutation
DROP(task: ITask) {
task.ref && task.ref--
if (!task.ref || !--task.ref) {
const cache = CACHE[task.id]
if (cache) {
const alive = this.config.alive
alive &&
(cache.t = setTimeout(() => {
REMOVE_TASK.call(this, task)
}, alive))
}
}
}

/// Action ///
Expand Down
Loading

0 comments on commit 2c25285

Please sign in to comment.