Skip to content

Commit

Permalink
fix: 修复参数合并问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesonhu committed Mar 26, 2020
1 parent 32c0fb2 commit 3925dd8
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 11 deletions.
1 change: 1 addition & 0 deletions dist/cMdEditor.css

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions dist/cMdEditor.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Cool-MD-Editor</title>
<style>
html,
body {
width:100%;
height:100%;
}
.wrap {
width: 80%;
height: 600px;
padding: 50px;
margin: 0 auto;
}
</style>
<link href="cMdEditor.css" rel="stylesheet"><link href="cMdEditor.css" rel="stylesheet"></head>
<body>
<div class="wrap">
<div class="cool-md-editor-wrap editor-theme-dark" id="editor-wrap"></div>
</div>

<!-- qiniu h5 upload -->
<script src="https://unpkg.com/qiniu-js@2.5.5/dist/qiniu.min.js"></script>
<script type="text/javascript" src="cMdEditor.js"></script>
<script>
const cMdEditor = new CMdEditor({
el: document.getElementById('editor-wrap'),
// lang: 'zh',
// shortcuts: {
// isOpen: false,
// },
qiniu: {
tokenApiUrl: 'http://121.42.230.245:9001/api/qiniu/test/get_token',
// region: 'z1',
// config: {},
// putExtra: {}
}
});
console.log(cMdEditor);
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "cool-md-editor",
"version": "1.2.1",
"version": "1.3.0",
"description": "a markedown editor width webpack & codemirror & marked & highlight",
"main": "dist/CMDEditor.js",
"unpkg": "dist/CMDEditor.js",
"main": "dist/cMDEditor.js",
"unpkg": "dist/cMDEditor.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --open --progress --colors",
Expand Down
6 changes: 3 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
// shortcuts: {
// isOpen: false,
// },
// qiniu: {
// tokenApiUrl: 'http://127.0.0.1:3001/api/qiniu/blog/get_token',
qiniu: {
tokenApiUrl: 'http://121.42.230.245:9001/api/qiniu/test/get_token',
// region: 'z1',
// config: {},
// putExtra: {}
// }
}
});
console.log(cMdEditor);
</script>
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,18 @@ class CMdEditor {
lang: 'zh',
// ========== 七牛 ==========
qiniu: {
tokenApiUrl: 'http://127.0.0.1:3001/api/qiniu/blog/get_token',
tokenApiUrl: 'http://127.0.0.1:3001/api/qiniu/test/get_token',
region: 'z1',
config: {},
putExtra: {}
}
}
Object.assign(defaultOptions, options);
this._options = defaultOptions;
// Object.assign(defaultOptions, options);
// this._options = defaultOptions;
this._options = UTIL.extend({}, defaultOptions, options);
this._options.$tools = $tools;
const _options = this._options;
console.log(this._options);

// 默认语言处理.
if (typeof _options.lang === 'string') {
Expand Down
6 changes: 4 additions & 2 deletions src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ const Util = {
/**
* Merge the properties of one object into another.
* 将一个对象的属性合并到另一个对象上.
* Object.assign({}, {person: {name: 1, age: 16}}, {person: {name:1}})
* 使用 Object.assign 需要处理多层数据前台的问题,这里就自行封装了.
*/
_mergeProperties(target, source) {
for (let property in source) {
if (source.hasOwnProperty(property)) {
if (souce[property] instanceof Array) {
if (source[property] instanceof Array) {
const value = target[property] instanceof Array ? target[property] : [];
target[property] = source[property].concat(value);
} else if (
source[property] != null &&
typeof source[property] === 'object' &&
source[property].constructor === Object )
{
target[property] = this._mergeProperties(target[property] || {}, souce[property]);
target[property] = this._mergeProperties(target[property] || {}, source[property]);
} else {
target[property] = source[property];
}
Expand Down

0 comments on commit 3925dd8

Please sign in to comment.