Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit 45c6e2b

Browse files
committed
optimize
1 parent 6687ec4 commit 45c6e2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4221
-3170
lines changed

.browserslistrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
> 1%
22
last 2 versions
3-
not ie <= 8

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VUE_APP_LFM_AXIOS_BASE_URL=
2-
VUE_APP_LFM_CSRF_TOKEN=
1+
VUE_APP_HOST=http://hub.ss
2+
VUE_APP_LFM_CSRF_TOKEN = OFF

.eslintrc.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
11
module.exports = {
22
root: true,
33
env: {
4+
browser: true,
45
node: true,
6+
es6: true,
7+
},
8+
globals: {
9+
moment: 'readonly',
510
},
611
extends: [
7-
'plugin:vue/essential',
8-
'@vue/airbnb',
12+
'plugin:unicorn/recommended',
13+
'plugin:sonarjs/recommended',
14+
'prettier',
915
],
16+
plugins: ['prettier', 'sonarjs', 'unicorn'],
17+
parserOptions: {
18+
parser: 'babel-eslint',
19+
sourceType: 'module',
20+
},
1021
rules: {
11-
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
22+
'global-require': 0,
23+
// Only allow debugger in development
1224
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
25+
// Only allow `console.log` in development
26+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
27+
'import/no-unresolved': 0,
28+
'no-unused-vars': [
29+
'error',
30+
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
31+
],
1332
'no-param-reassign': [
1433
'error',
1534
{
16-
'props': true,
17-
'ignorePropertyModificationsFor': [
18-
'state',
19-
'acc',
20-
'e',
21-
'ctx',
22-
'req',
23-
'request',
24-
'res',
25-
'response',
26-
'$scope',
27-
],
35+
props: true,
36+
ignorePropertyModificationsFor: ['state'],
2837
},
2938
],
30-
'max-len': 'off',
31-
'vue/no-use-v-if-with-v-for': [
32-
'error', {
33-
'allowUsingIterationVar': true,
34-
}],
35-
},
36-
parserOptions: {
37-
parser: 'babel-eslint',
39+
'no-underscore-dangle': 'warn',
40+
'sonarjs/no-identical-expressions': 'error',
41+
'sonarjs/no-identical-functions': 'warn',
42+
'sonarjs/cognitive-complexity': ['warn', 15],
43+
'unicorn/filename-case': [
44+
'error',
45+
{
46+
cases: {
47+
camelCase: true,
48+
pascalCase: true,
49+
},
50+
},
51+
],
52+
'unicorn/prevent-abbreviations': 'warn',
3853
},
39-
};
54+
}

.prettierrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"singleQuote": true,
6+
"trailingComma": "es5",
7+
"bracketSpacing": true,
8+
"jsxBracketSameLine": false,
9+
"semi": false,
10+
"requirePragma": false,
11+
"proseWrap": "preserve",
12+
"arrowParens": "avoid"
13+
}

babel.config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
module.exports = {
2-
presets: [
3-
'@vue/cli-plugin-babel/preset',
2+
presets: ['@vue/cli-plugin-babel/preset'],
3+
plugins: [
4+
'@babel/plugin-transform-runtime',
5+
'@babel/plugin-proposal-optional-chaining',
6+
'@babel/plugin-proposal-nullish-coalescing-operator',
7+
[
8+
'component',
9+
{
10+
libraryName: 'element-ui',
11+
styleLibraryName: 'theme-chalk',
12+
},
13+
],
414
],
5-
};
15+
}

demo/App.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<file-manager/>
3+
</template>
4+
5+
<script>
6+
7+
export default {
8+
name: 'App',
9+
}
10+
</script>

demo/browser.helpers.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { isObject } from '@feugene/mu/src/is'
2+
3+
export default function() {
4+
window.l = (...value) => {
5+
console.log(...value)
6+
}
7+
8+
window.ll = (...value) => {
9+
console.group('ll')
10+
11+
Array.from(value).forEach(item => {
12+
if (isObject(item)) {
13+
console.dir(item)
14+
} else if (item instanceof Error || item instanceof HTMLElement || item instanceof DOMImplementation) {
15+
console.error(item)
16+
} else {
17+
console.log(item)
18+
}
19+
})
20+
21+
console.groupEnd()
22+
}
23+
24+
window.d = (...value) => {
25+
console.dir(...value)
26+
}
27+
}

demo/main.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Vue from 'vue'
2+
import Vuex from 'vuex'
3+
import FileManager from '@/init'
4+
import request from './request'
5+
import App from './App'
6+
import setBrowserHelpers from './browser.helpers'
7+
8+
Vue.use(Vuex)
9+
10+
// create new store
11+
const store = new Vuex.Store({
12+
strict: process.env.NODE_ENV !== 'production',
13+
})
14+
15+
Vue.config.productionTip = process.env.NODE_ENV === 'production'
16+
Vue.prototype.$request = request(store)
17+
18+
Vue.use(FileManager, { store })
19+
setBrowserHelpers()
20+
21+
new Vue({
22+
store,
23+
render: (h) => h(App),
24+
}).$mount('#app')

demo/request/index.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import buildBaseRequest from '@feugene/request'
2+
import AuthInterceptor from './interceptors/AuthInterceptor'
3+
import { LoadingRequestInterceptor, LoadingResponseInterceptor } from '@/request/LoadingInterceptor'
4+
5+
function initBaseUrl() {
6+
let baseUrl
7+
if (process.env.VUE_APP_HOST) {
8+
baseUrl = process.env.VUE_APP_HOST
9+
} else {
10+
baseUrl = `${window.location.protocol}//${window.location.hostname}`
11+
12+
if (window.location.port.length) {
13+
baseUrl += `:${window.location.port}`
14+
}
15+
}
16+
baseUrl += `/api/admin/file-manager`
17+
18+
return baseUrl
19+
}
20+
21+
function initHeaders() {
22+
const headers = {
23+
'X-Requested-With': 'XMLHttpRequest',
24+
}
25+
26+
// off laravel csrf-token if need
27+
if (process.env.VUE_APP_LFM_CSRF_TOKEN !== 'OFF') {
28+
// Laravel CSRF token
29+
const token = document.head.querySelector('meta[name="csrf-token"]')
30+
31+
if (!token) {
32+
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token')
33+
} else {
34+
headers['X-CSRF-TOKEN'] = token.content
35+
}
36+
}
37+
38+
return headers
39+
}
40+
41+
function initSettings() {
42+
return {
43+
baseURL: initBaseUrl(),
44+
headers: initHeaders(),
45+
}
46+
}
47+
48+
// initiate headers, if not set manually
49+
export const defaultConfig = initSettings()
50+
51+
const request = (store) => (config = {}) => {
52+
const mergedConfig = { ...defaultConfig, ...config }
53+
54+
mergedConfig.store = store
55+
if (config.auth) {
56+
mergedConfig.auth = 'secret_token'
57+
}
58+
59+
mergedConfig.afterInitFn = (instance) => {
60+
instance.registerRequestInterceptors(LoadingRequestInterceptor)
61+
instance.registerResponseInterceptors(LoadingResponseInterceptor)
62+
63+
if (instance.config.auth) {
64+
instance.registerRequestInterceptors(AuthInterceptor)
65+
}
66+
67+
/*if (isFunction(instance.config.responseWrap)) {
68+
instance.registerResponseInterceptors(WrapperInterceptor)
69+
}*/
70+
}
71+
/*
72+
config.responseWrap.fn = (instance) => {
73+
instance.registerResponseInterceptors(WrapperInterceptor)
74+
}*/
75+
76+
return buildBaseRequest(mergedConfig)
77+
}
78+
79+
export default request
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const AuthInterceptor = (options) =>
2+
(config) => {
3+
if (options.auth) {
4+
// eslint-disable-next-line no-param-reassign
5+
config.headers.Authorization = options.auth
6+
} else {
7+
// eslint-disable-next-line no-param-reassign
8+
delete config.headers.Authorization
9+
}
10+
}
11+
12+
export default AuthInterceptor

package.json

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,53 @@
1212
"license": "MIT",
1313
"main": "src/init.js",
1414
"scripts": {
15-
"serve": "vue-cli-service serve",
15+
"serve": "vue-cli-service serve ./demo/main.js",
1616
"build": "vue-cli-service build",
1717
"lint": "vue-cli-service lint",
1818
"test:unit": "vue-cli-service test:unit"
1919
},
2020
"dependencies": {
21-
"axios": "^0.21.1",
22-
"codemirror": "^5.59.2",
23-
"core-js": "^3.9.0",
21+
"codemirror": "^5.59.4",
2422
"cropperjs": "^1.5.11",
2523
"plyr": "^3.6.4",
24+
"vue-codemirror": "^4.0.6"
25+
},
26+
"peerDependencies": {
27+
"@feugene/mu": "^2.20",
28+
"@feugene/request": "^0.0.3",
29+
"axios": "^0.21.1",
30+
"core-js": "^3.9.0",
31+
"element-ui": "^2.15.1",
2632
"vue": "^2.6.12",
27-
"vue-codemirror": "^4.0.6",
2833
"vuex": "^3.6.2"
2934
},
3035
"devDependencies": {
31-
"@vue/cli-plugin-babel": "~4.4.6",
32-
"@vue/cli-plugin-eslint": "~4.4.6",
33-
"@vue/cli-plugin-vuex": "~4.4.6",
34-
"@vue/cli-service": "~4.4.6",
35-
"@vue/eslint-config-airbnb": "^5.0.2",
36+
"@babel/plugin-proposal-optional-chaining": "^7.13.0",
37+
"@babel/plugin-transform-runtime": "^7.13.5",
38+
"@feugene/mu": "^2.20",
39+
"@feugene/request": "^0.0.3",
40+
"@vue/cli-plugin-babel": "~4.5.11",
41+
"@vue/cli-plugin-eslint": "~4.5.11",
42+
"@vue/cli-service": "~4.5.11",
43+
"@vue/eslint-config-airbnb": "^5.3.0",
44+
"axios": "^0.21.1",
3645
"babel-eslint": "^10.1.0",
37-
"eslint": "^6.8.0",
38-
"eslint-plugin-import": "^2.22.0",
39-
"eslint-plugin-vue": "^6.2.2",
40-
"node-sass": "^4.14.1",
41-
"sass-loader": "^8.0.2",
42-
"vue-template-compiler": "^2.6.12"
46+
"babel-plugin-component": "^1.1.1",
47+
"core-js": "^3.9.0",
48+
"element-ui": "^2.15.1",
49+
"eslint": "7.20.0",
50+
"eslint-config-prettier": "^8.0.0",
51+
"eslint-plugin-import": "^2.22.1",
52+
"eslint-plugin-prettier": "^3.3.1",
53+
"eslint-plugin-sonarjs": "^0.6.0",
54+
"eslint-plugin-unicorn": "^28.0.2",
55+
"eslint-plugin-vue": "^7.6.0",
56+
"node-sass": "^5.0.0",
57+
"prettier": "^2.2.1",
58+
"prettier-eslint": "^12.0.0",
59+
"sass-loader": "^10.1.1",
60+
"vue": "^2.6.12",
61+
"vue-template-compiler": "^2.6.12",
62+
"vuex": "^3.6.2"
4363
}
4464
}

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</noscript>
1818
<div class="container">
1919
<div style="height: 600px;">
20-
<div id="fm"></div>
20+
<div id="app"></div>
2121
</div>
2222
</div>
2323
<!-- built files will be auto injected -->

0 commit comments

Comments
 (0)