-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/performance-enhancement-jan-30-2020' into develop
- Loading branch information
Showing
19 changed files
with
532 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Component, Vue } from 'vue-property-decorator' | ||
// eslint-disable-next-line no-unused-vars | ||
import { MultiWindowOptions } from '@/mixins/multi-window/multi-window-options' | ||
|
||
/** | ||
* Multi window mixin | ||
* | ||
* Can i use mixins global in vue? i am use typescript with vue | ||
* @see <a href='https://github.com/kaorun343/vue-property-decorator/issues/226#issuecomment-515568960'>GitHub</a> | ||
*/ | ||
@Component | ||
export class MultiWindow extends Vue { | ||
private $multiWindowOptions: MultiWindowOptions = { | ||
delayClosingWindow: true, | ||
callback: '' | ||
} | ||
|
||
mounted () { | ||
this.$data.$multiWindowOptions.delayClosingWindow = this.$route?.query?.delayClosingWindow === 'true' | ||
this.$data.$multiWindowOptions.callback = this.$route?.query?.callback | ||
} | ||
|
||
openWindow (context: Vue, url: string, multiWindowOptions?: MultiWindowOptions): void { | ||
// Set default delayClosingWindow as true | ||
if (multiWindowOptions?.delayClosingWindow === undefined) { | ||
// @ts-ignore | ||
multiWindowOptions.delayClosingWindow = true | ||
} | ||
const path = /\/$/.test(url) ? url : `${url}/` | ||
// the value of process.env.BASE_URL is equal to the `publicPath` configured in vue.config.js | ||
const baseUrl = process.env.BASE_URL | ||
const target = /^(http|https):\/\//.test(path) ? url : `${baseUrl}#${url}` | ||
// Passing information to opened window by query string | ||
let queryString = '' | ||
for (const key in multiWindowOptions) { | ||
// Determines whether an object has a property with the specified name. | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!multiWindowOptions.hasOwnProperty(key)) { | ||
break | ||
} | ||
const val = ((multiWindowOptions[key] === null) || (multiWindowOptions[key] === undefined) ? '' : multiWindowOptions[key]) | ||
queryString += queryString === '' ? `?${key}=${val}` : `&${key}=${val}` | ||
} | ||
setTimeout(() => { | ||
const newWindow = window.open(`${target}${queryString}`, multiWindowOptions?.windowTarget) | ||
if (!newWindow) { | ||
window.alert('Please give us permission to open a new page!') | ||
throw new Error('Failed to gain permission to open a new page!') | ||
} else { | ||
newWindow.opener.$vue = context | ||
} | ||
}, 600) | ||
} | ||
|
||
windowBack (argument?: any): void { | ||
const context = window?.opener?.$vue | ||
const callback = this.$data.$multiWindowOptions.callback | ||
const delayClosingWindow = this.$data.$multiWindowOptions.delayClosingWindow | ||
if (!context) { | ||
this.$toast.error('ERROR: Cannot find context!') | ||
// window.alert('ERROR: Cannot find context!') | ||
throw new Error('Cannot find context!') | ||
} | ||
// Check whether opener's callback is valid | ||
if (callback && typeof context[callback] === 'function') { | ||
context[callback](argument) | ||
} else { | ||
this.$toast.error('ERROR: Cannot find callback!') | ||
// window.alert('ERROR: Cannot find callback!') | ||
throw new Error('Cannot find callback!') | ||
} | ||
if (delayClosingWindow) { | ||
setTimeout(() => { | ||
window.close() | ||
}, 300) | ||
} else { | ||
window.close() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Multi Window Options | ||
*/ | ||
export interface MultiWindowOptions { | ||
/** | ||
* A DOMString specifying the name of the browsing context (window, <iframe> or tab) into which to load the specified resource; | ||
* if the name doesn't indicate an existing context, a new window is created and is given the name specified by windowName. | ||
*/ | ||
windowTarget?: string | ||
|
||
/** | ||
* Whether delay closing opened window for 300 ms. Default: true | ||
*/ | ||
delayClosingWindow?: boolean | ||
|
||
/** | ||
* Vue instance of opener callback function name | ||
*/ | ||
callback?: string | ||
|
||
/** | ||
* Other data | ||
*/ | ||
[key: string]: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.