Skip to content

Commit 3d072bd

Browse files
gongjsvanoneang
authored andcommitted
Error (#227)
* Update README.md * Tinymce (#214) * Update README.md * Update axios.js * feat:富文本 Tinymce * fix:去掉tinymce标识 * update:新增富文本部分内置插件 * fix:富文本上传图片加入token验证 * fix:自动化导入富文本插件 * fix:修复没有分组时,新建用户选择分组的时候会显示0的bug (#221) * build(.eslintrc.js): 去掉'linebreak-style': [0, 'error', 'windows'] airbnb校验规则会要求项目使用 LF 换行符, git for windows 在默认配置下会将签出的代码转换成 CRLF。此处应要求 windwos 开发者关闭 git 自动转换功能。 * chore(*): 更新依赖, 修复eslint不符合的地方 * feat(Login): 登录界面移动适配 * fix:全局错误处理
1 parent 239289f commit 3d072bd

File tree

15 files changed

+7631
-7277
lines changed

15 files changed

+7631
-7277
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = {
1313
rules: {
1414
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
1515
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
16-
'linebreak-style': [0, 'error', 'windows'],
1716
'import/extensions': 0, // import不需要写文件扩展名
1817
'import/no-unresolved': 0,
1918
// 'import/no-duplicates': 0,

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ QQ群搜索:林间有风 或 643205479
8989

9090
## 版本日志
9191

92+
<<<<<<< HEAD
9293
最新版本 `0.2.0`
9394

9495
### 0.2.0
9596

9697
1. `A` 新增图像上传、图像预览、富文本等自定义组件
9798
2. `A` 新增 lin-cms-ui 多个基础组件
99+
=======
100+
最新版本 `0.1.0-beta.3`
101+
>>>>>>> 0b890cda57f1aaa11af9315d031ae15fae4def51
98102
99103
### 0.1.0-beta.3
100104

package-lock.json

Lines changed: 7535 additions & 7178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,54 @@
1313
"test:unit": "vue-cli-service test:unit"
1414
},
1515
"dependencies": {
16-
"@babel/polyfill": "^7.2.5",
16+
"@babel/polyfill": "^7.4.4",
1717
"@tinymce/tinymce-vue": "^2.1.0",
1818
"axios": "~0.18.0",
19-
"element-ui": "^2.8.2",
20-
"event-source-polyfill": "^0.0.16",
19+
"element-ui": "^2.10.1",
20+
"event-source-polyfill": "^1.0.7",
2121
"fastscan": "^1.0.4",
2222
"good-storage": "^1.1.0",
2323
"js-cookie": "^2.2.0",
2424
"lodash": "^4.17.14",
2525
"moment": "^2.24.0",
2626
"photoswipe": "^4.1.2",
2727
"screenfull": "^4.2.0",
28-
"tinymce": "^5.0.9",
29-
"vue": "^2.6.8",
28+
"tinymce": "^5.0.12",
29+
"vue": "^2.6.10",
3030
"vue-awesome-swiper": "^3.1.3",
3131
"vue-croppa": "^1.3.8",
32-
"vue-router": "~3.0.1",
33-
"vuex": "~3.0.1",
34-
"vuex-persist": "^2.0.0"
32+
"vue-router": "^3.0.7",
33+
"vuex": "^3.1.1",
34+
"vuex-persist": "^2.0.1"
3535
},
3636
"devDependencies": {
37-
"@vue/cli-plugin-babel": "^3.4.0",
38-
"@vue/cli-plugin-eslint": "^3.4.0",
39-
"@vue/cli-plugin-unit-jest": "^3.7.0",
40-
"@vue/cli-service": "^3.4.0",
41-
"@vue/eslint-config-airbnb": "^4.0.0",
37+
"@vue/cli-plugin-babel": "^3.9.2",
38+
"@vue/cli-plugin-eslint": "^3.9.2",
39+
"@vue/cli-plugin-unit-jest": "^3.9.0",
40+
"@vue/cli-service": "^3.9.2",
41+
"@vue/eslint-config-airbnb": "^4.0.1",
4242
"@vue/test-utils": "1.0.0-beta.29",
4343
"babel-core": "7.0.0-bridge.0",
44-
"babel-eslint": "^10.0.1",
45-
"babel-jest": "^23.6.0",
44+
"babel-eslint": "^10.0.2",
45+
"babel-jest": "^24.8.0",
4646
"babel-plugin-component": "^1.1.1",
4747
"chalk": "^2.4.2",
4848
"child_process": "^1.0.2",
4949
"cz-conventional-changelog": "^2.1.0",
50-
"directory-tree": "^2.2.1",
51-
"ejs": "^2.6.1",
52-
"eslint": "^5.8.0",
53-
"eslint-plugin-vue": "^5.0.0",
54-
"fs-extra": "^7.0.1",
55-
"inquirer": "^6.2.2",
56-
"js-yaml": "^3.12.2",
50+
"directory-tree": "^2.2.3",
51+
"ejs": "^2.6.2",
52+
"eslint": "^6.0.1",
53+
"eslint-plugin-vue": "^5.2.3",
54+
"fs-extra": "^8.1.0",
55+
"inquirer": "^6.5.0",
56+
"js-yaml": "^3.13.1",
5757
"node-sass": "^4.12.0",
5858
"sass-loader": "^7.1.0",
59-
"semver": "^5.6.0",
59+
"semver": "^6.2.0",
6060
"shelljs": "^0.8.3",
6161
"validate-npm-package-name": "^3.0.0",
6262
"vue-markdown-loader": "^2.4.1",
63-
"vue-template-compiler": "^2.6.8",
63+
"vue-template-compiler": "^2.6.10",
6464
"yaml-front-matter": "^4.0.0"
6565
},
6666
"postcss": {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// eslint-disable-next-line
2+
const importAll = (requireContext) => requireContext.keys().forEach(requireContext)
3+
try {
4+
// 导入所有插件
5+
importAll(require.context('../../../../node_modules/tinymce/plugins', true))
6+
} catch (err) {
7+
console.log(err)
8+
}

src/components/base/tinymce/index.vue

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
<editor id="tinymceEditor" :init="tinymceInit" v-model="content" :key="tinymceFlag"></editor>
44
</div>
55
</template>
6-
76
<script>
87
// eslint-disable-next-line
98
import tinymce from 'tinymce/tinymce'
109
import Editor from '@tinymce/tinymce-vue'
1110
import 'tinymce/themes/silver/theme'
12-
import 'tinymce/plugins/textcolor'
13-
import 'tinymce/plugins/advlist'
14-
import 'tinymce/plugins/table'
15-
import 'tinymce/plugins/lists'
16-
import 'tinymce/plugins/paste'
17-
import 'tinymce/plugins/preview'
18-
import 'tinymce/plugins/fullscreen'
19-
import 'tinymce/plugins/image'
20-
import 'tinymce/plugins/code'
21-
import 'tinymce/plugins/link'
11+
import './importAll'
2212
2313
export default {
2414
name: 'TinymceEditor',
@@ -39,6 +29,11 @@ export default {
3929
type: Boolean,
4030
default: true,
4131
},
32+
toolbar: {
33+
type: String,
34+
// eslint-disable-next-line
35+
default: ' undo redo |formatselect | bold italic strikethrough forecolor backcolor formatpainter | link image | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | preview fullscreen code',
36+
},
4237
},
4338
components: {
4439
Editor,
@@ -64,32 +59,25 @@ export default {
6459
statusbar: false, // 隐藏编辑器底部的状态栏
6560
paste_data_images: true, // 允许粘贴图像
6661
menubar: this.showMenubar, // 隐藏最上方menu
67-
plugins: 'advlist table lists paste preview fullscreen image code link',
6862
// eslint-disable-next-line
69-
toolbar:' undo redo |fontselect fontsizeselect forecolor backcolor bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | link image | h1 h2 h3 blockquote table numlist bullist | preview fullscreen code',
63+
plugins: 'print fullpage searchreplace autolink directionality visualblocks visualchars template codesample charmap hr pagebreak nonbreaking anchor toc insertdatetime wordcount textpattern help advlist table lists paste preview fullscreen image imagetools code link',
64+
toolbar: this.toolbar,
7065
// eslint-disable-next-line
7166
images_upload_handler: async function(blobInfo, success, failure) {
72-
// eslint-disable-next-line
73-
let json
74-
const xhr = new XMLHttpRequest()
75-
xhr.withCredentials = false
76-
xhr.open('POST', `${_this.upload_url}`)
77-
// eslint-disable-next-line
78-
xhr.onload = function() {
79-
if (xhr.status !== 200) {
80-
failure(`HTTP Error: ${xhr.status}`)
81-
return
82-
}
83-
json = JSON.parse(xhr.responseText)
84-
if (json[0] && json[0].url) {
85-
success(json[0].url)
86-
} else {
87-
failure(`Invalid JSON: ${xhr.responseText}`)
67+
const file = new File([blobInfo.blob()], blobInfo.filename(), {
68+
type: 'image/*',
69+
})
70+
_this.$axios({
71+
method: 'post',
72+
url: '/cms/file/',
73+
data: {
74+
file,
75+
},
76+
}).then((res) => {
77+
if (res[0] && res[0].url) {
78+
success(res[0].url)
8879
}
89-
}
90-
const formData = new FormData()
91-
formData.append('file', blobInfo.blob(), blobInfo.filename())
92-
xhr.send(formData)
80+
}).catch(err => failure(err))
9381
},
9482
}
9583
},

src/components/layout/SideBar.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@
8080
</template>
8181

8282
<script>
83-
import Utils from '@/lin/utils/util'
84-
/* eslint-disable no-restricted-syntax */
8583
import { mapGetters } from 'vuex'
84+
import Utils from '@/lin/utils/util'
8685
8786
export default {
8887
props: ['isCollapse'],

src/components/layout/User.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@
106106

107107
<script>
108108
import { mapActions, mapGetters } from 'vuex'
109-
import User from '@/lin/models/user'
110109
import Vue from 'vue'
111110
import Croppa from 'vue-croppa'
111+
import User from '@/lin/models/user'
112112
import 'vue-croppa/dist/vue-croppa.css'
113113
import defaultAvatar from '@/assets/img/user/user.png'
114114

src/config/error-code.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
const stateCode = {
3-
0: '成功',
4-
1007: '未知错误',
3+
777: '未知错误',
54
999: '服务器未知错误',
6-
9999: '失败',
75
10000: '认证失败',
86
10020: '资源不存在',
97
10030: '参数错误',

src/lin/plugins/axios.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import Vue from 'vue'
33
import axios from 'axios'
44
import Config from '@/config'
5+
import ErrorCode from '@/config/error-code'
56
import store from '@/store'
67
import { getToken } from '@/lin/utils/token'
8+
// eslint-disable-next-line import/no-cycle
79
import User from '@/lin/models/user'
810

911

@@ -13,14 +15,14 @@ import User from '@/lin/models/user'
1315
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
1416

1517
const config = {
16-
baseURL: Config.baseUrl || process.env.apiUrl || '',
18+
baseURL: Config.baseURL || process.env.apiUrl || '',
1719
timeout: 5 * 1000, // 请求超时时间设置
1820
crossDomain: true,
1921
// withCredentials: true, // Check cross-site Access-Control
2022
// 定义可获得的http响应状态码
2123
// return true、设置为null或者undefined,promise将resolved,否则将rejected
2224
validateStatus(status) {
23-
return status >= 200 && status < 500
25+
return status >= 200 && status < 510
2426
},
2527
}
2628

@@ -109,10 +111,10 @@ _axios.interceptors.request.use((originConfig) => {
109111

110112
// Add a response interceptor
111113
_axios.interceptors.response.use(async (res) => {
114+
let { error_code, msg } = res.data // eslint-disable-line
112115
if (res.status.toString().charAt(0) === '2') {
113116
return res.data
114117
}
115-
116118
return new Promise(async (resolve, reject) => {
117119
// 将本次失败请求保存
118120
const { params, url, method } = res.config
@@ -121,25 +123,20 @@ _axios.interceptors.response.use(async (res) => {
121123
url,
122124
method,
123125
})
124-
125-
// 处理 API 异常
126-
let { error_code, msg } = res.data // eslint-disable-line
127-
if (msg instanceof Object) {
128-
let showMsg = ''
129-
Object.getOwnPropertyNames(msg).forEach((key, index) => {
130-
if (index === 0) {
131-
showMsg = msg[key] // 如果是数组,展示第一条
132-
}
133-
})
134-
msg = showMsg
126+
// 用户自己try catch
127+
if (params.handleError) {
128+
reject(res)
129+
return
135130
}
136-
// 如果令牌无效或者是refreshToken相关异常
131+
// 处理 API 异常
137132
if (error_code === 10000 || error_code === 10100) {
138133
setTimeout(() => {
139134
store.dispatch('loginOut')
140135
const { origin } = window.location
141136
window.location.href = origin
142137
}, 1500)
138+
resolve(null)
139+
return
143140
}
144141
// 令牌相关,刷新令牌
145142
if (error_code === 10040 || error_code === 10050) {
@@ -153,12 +150,20 @@ _axios.interceptors.response.use(async (res) => {
153150
return
154151
}
155152
}
156-
153+
const errorArr = Object.entries(ErrorCode).filter(v => v[0] === error_code.toString())
154+
// 匹配到自定义的错误码
155+
if (errorArr.length > 0) {
156+
if (errorArr[0][1] !== '') {
157+
msg = errorArr[0][1] // eslint-disable-line
158+
} else {
159+
msg = ErrorCode['777']
160+
}
161+
}
157162
Vue.prototype.$message({
158-
message: msg || '未知的error_code',
163+
message: msg,
159164
type: 'error',
160165
})
161-
reject(res.data)
166+
resolve(null)
162167
})
163168
}, (error) => {
164169
if (!error.response) {

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '@/lin/filter'
77
import '@/lin/plugins'
88
import '@/lin/directives'
99

10+
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition'
1011
import router from '@/router'
1112
import store from '@/store'
1213
import App from '@/App.vue'
@@ -15,10 +16,10 @@ import StickyTop from '@/components/base/sticky-top/sticky-top'
1516
import LIcon from '@/components/base/icon/lin-icon'
1617
import SourceCode from '@/components/base/source-code/source-code'
1718

18-
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition'
1919

2020
import '@/assets/styles/index.scss' // eslint-disable-line
2121
import '@/assets/styles/realize/element-variables.scss'
22+
import 'element-ui/lib/theme-chalk/display.css'
2223

2324
Vue.config.productionTip = false
2425

src/plugins/custom/views/Tinymce.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</template>
99

1010
<script>
11+
1112
import Tinymce from '@/components/base/tinymce'
1213
1314
export default {

src/views/admin/user/UserInfo.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
>
2828
<el-input size="medium" clearable type="password" v-model="form.confirm_password" autocomplete="off"></el-input>
2929
</el-form-item>
30-
<el-form-item v-if="pageType !== 'password'" label="选择分组">
31-
<el-select size="medium" filterable v-model="form.group_id" placeholder="请选择分组">
30+
<el-form-item v-if="pageType !== 'password'" label="选择分组" >
31+
<el-select size="medium" filterable v-model="form.group_id" :disabled="groups.length === 0" placeholder="请选择分组">
3232
<el-option
3333
v-for="item in groups"
3434
:key="item.id"
@@ -122,7 +122,7 @@ export default {
122122
password: '',
123123
confirm_password: '',
124124
email: '',
125-
group_id: 0,
125+
group_id: '请先创建分组',
126126
},
127127
// 验证规则
128128
rules: {

src/views/log/Log.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
</template>
6868

6969
<script>
70+
import { mapGetters } from 'vuex'
7071
import log from 'lin/models/log'
72+
import { searchLogKeyword } from 'lin/utils/search'
7173
import LinSearch from '@/components/base/search/lin-search'
7274
import LinDatePicker from '@/components/base/date-picker/lin-date-picker'
73-
import { searchLogKeyword } from 'lin/utils/search'
74-
import { mapGetters } from 'vuex'
7575
7676
export default {
7777
components: {

0 commit comments

Comments
 (0)