@ -0,0 +1,171 @@
|
||||
{ |
||||
"extends": "eslint:recommended", |
||||
"rules": { |
||||
// 声明 |
||||
"no-use-before-define": "error", |
||||
//禁止定义前使用 |
||||
|
||||
// 对象 |
||||
"no-dupe-keys": "error", |
||||
// 禁止在对象字面量中出现重复的键 |
||||
"quote-props": [ |
||||
"error", |
||||
"as-needed" |
||||
], |
||||
// 对象属性只在需要的时候加引号 |
||||
|
||||
// 字符串 |
||||
"quotes": [ |
||||
"error", |
||||
"double", |
||||
{ |
||||
"allowTemplateLiterals": true |
||||
} |
||||
], |
||||
// 字符串开头和结束使用双引号 |
||||
"no-useless-concat": "error", |
||||
// 禁止没有必要的字符拼接 |
||||
"no-useless-escape": "error", |
||||
// 禁用不必要的转义 |
||||
|
||||
// 函数 |
||||
"no-dupe-args": "error", |
||||
// 禁止在 function 定义中出现重复的参数 |
||||
"space-before-function-paren": "error", |
||||
// 函数括号前必须要有空格 |
||||
|
||||
// 变量 |
||||
"no-undef": "error", |
||||
// 禁止使用未声明的变量 |
||||
|
||||
// 比较运算符 & 相等运算符 |
||||
"eqeqeq": "error", |
||||
// 使用 === 和 !== 代替 == 和 != |
||||
"no-unneeded-ternary": "error", |
||||
//禁止可以在有更简单的可替代的表达式时使用三元操作符 |
||||
|
||||
// 条件 |
||||
"default-case": "error", |
||||
// 要求 Switch 语句中有 Default 分支 |
||||
"no-else-return": "error", |
||||
// 如果 if 块中包含了一个 return 语句,else 块就成了多余的了。可以将其内容移至块外 |
||||
|
||||
// 代码块 |
||||
"brace-style": [ |
||||
"error", |
||||
"1tbs", |
||||
{ |
||||
"allowSingleLine": true |
||||
} |
||||
], |
||||
// 代码块左括号紧跟上一行结束 |
||||
"curly": [ |
||||
"error", |
||||
"multi-line" |
||||
], |
||||
// if、else if、else、for、while强制使用大括号,但允许在单行中省略大括号 |
||||
|
||||
// 注释 |
||||
"spaced-comment": "error", |
||||
// 注释前有空格 |
||||
|
||||
// 空白 |
||||
"indent": [ |
||||
"error", |
||||
4, |
||||
{ |
||||
"SwitchCase": 1 |
||||
} |
||||
], |
||||
// 缩进控制4空格 |
||||
"no-mixed-spaces-and-tabs": "error", |
||||
// 禁止使用 空格 和 tab 混合缩进 |
||||
"space-before-blocks": [ |
||||
"error", |
||||
"always" |
||||
], |
||||
// 语句块之前的需要有空格 |
||||
"space-infix-ops": [ |
||||
"error", |
||||
{ |
||||
"int32Hint": false |
||||
} |
||||
], |
||||
// 要求中缀操作符周围有空格,设置 int32Hint 选项为 true (默认 false) 允许 a|0 不带空格 |
||||
"no-trailing-spaces": [ |
||||
"error", |
||||
{ |
||||
"skipBlankLines": true |
||||
} |
||||
], |
||||
// 禁用行尾空格 |
||||
"key-spacing": [ |
||||
"error", |
||||
{ |
||||
"afterColon": true |
||||
} |
||||
], |
||||
// 要求在对象字面量的冒号和值之间存在至少有一个空格 |
||||
|
||||
|
||||
// 逗号 |
||||
"comma-style": "error", |
||||
// 逗号必须放在行末 |
||||
"comma-dangle": [ |
||||
"error", |
||||
"never" |
||||
], |
||||
// 多行对象字面量中要求不要拖尾逗号 |
||||
"comma-spacing": [ |
||||
"error", |
||||
{ |
||||
"before": false, |
||||
"after": true |
||||
} |
||||
], |
||||
//在变量声明、数组字面量、对象字面量、函数参数 和 序列中禁止在逗号前使用空格,要求在逗号后使用一个或多个空格 |
||||
|
||||
|
||||
// 分号 |
||||
"semi": "error", |
||||
//不得省略语句结束的分号 |
||||
"semi-spacing": [ |
||||
"error", |
||||
{ |
||||
"before": false, |
||||
"after": true |
||||
} |
||||
], |
||||
//禁止分号周围的空格 |
||||
"no-extra-semi": "error", |
||||
// 禁用不必要的分号 |
||||
|
||||
|
||||
// 类型转换 |
||||
"no-extra-boolean-cast": "error", |
||||
// 禁止不必要的布尔类型转换 |
||||
|
||||
|
||||
// 其他最佳实践或规范 |
||||
"no-unexpected-multiline": "error", |
||||
// 禁止使用令人困惑的多行表达式 |
||||
"no-unreachable": "error", |
||||
// 禁止在 return、throw、continue 和 break 语句后出现不可达代码 |
||||
"valid-typeof": "error", |
||||
// 强制 typeof 表达式与有效的字符串进行比较 |
||||
"no-new-wrappers": "error" |
||||
// 禁止通过 new 操作符使用 String、Number 和 Boolean |
||||
}, |
||||
"globals": { |
||||
"window": true, |
||||
"BI": true, |
||||
"BICst": true, |
||||
"Data": true, |
||||
"Fix": true, |
||||
"module": true, |
||||
"describe": true, |
||||
"it": true, |
||||
"expect": true, |
||||
"Dec": true |
||||
} |
||||
} |
@ -0,0 +1,121 @@
|
||||
module.exports = function (grunt) { |
||||
// Project configuration.
|
||||
grunt.initConfig({ |
||||
pkg: grunt.file.readJSON("package.json"), |
||||
concat: { |
||||
options: { |
||||
separator: "" |
||||
}, |
||||
bundleJs: { |
||||
src: [ |
||||
"src/modules/**/*.js", |
||||
"src/index.js" |
||||
], |
||||
dest: "dist/bundle.js" |
||||
}, |
||||
bundleCss: { |
||||
src: ["src/css/**/*.css"], |
||||
dest: "dist/bundle.css" |
||||
} |
||||
}, |
||||
|
||||
less: { |
||||
main: { |
||||
expand: true, |
||||
cwd: "src/modules", |
||||
src: ["**/*.less"], |
||||
dest: "src/css/", |
||||
ext: ".css" |
||||
}, |
||||
dev: { |
||||
options: { |
||||
compress: true, |
||||
yuicompress: false |
||||
} |
||||
} |
||||
}, |
||||
|
||||
uglify: { |
||||
options: { |
||||
banner: |
||||
"/*! <%= pkg.name %> <%= grunt.template.today(\"dd-mm-yyyy\") %> */\n" |
||||
}, |
||||
dist: { |
||||
files: { |
||||
"dist/bundle.min.js": ["<%= concat.bundleJs.dest %>"] |
||||
} |
||||
} |
||||
}, |
||||
|
||||
cssmin: { |
||||
bundleCss: { |
||||
src: "<%= concat.bundleCss.dest %>", |
||||
|
||||
dest: "dist/bundle.min.css" |
||||
} |
||||
}, |
||||
|
||||
jshint: { |
||||
files: ["src/**/*.js"], |
||||
options: { |
||||
globals: { |
||||
$: true, |
||||
jQuery: true, |
||||
console: true, |
||||
module: true, |
||||
document: true |
||||
}, |
||||
browser: true, |
||||
expr: true |
||||
} |
||||
}, |
||||
watch: { |
||||
scripts: { |
||||
files: ["src/**/*.js", "src/**/*.less"], |
||||
tasks: ["less", "concat"], |
||||
options: { |
||||
spanw: true, |
||||
interrupt: true |
||||
} |
||||
}, |
||||
livereload: { |
||||
options: { |
||||
livereload: "<%= connect.options.livereload %>" |
||||
}, |
||||
files: ["src/**/*.js", "src/**/*.less"] |
||||
} |
||||
}, |
||||
connect: { |
||||
options: { |
||||
port: 9000, |
||||
open: true, |
||||
livereload: 35799, |
||||
// Change this to '0.0.0.0' to access the server from outside
|
||||
hostname: "localhost" |
||||
}, |
||||
server: { |
||||
options: { |
||||
port: 9009, |
||||
base: "./" |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
|
||||
grunt.loadNpmTasks("grunt-contrib-uglify"); |
||||
grunt.loadNpmTasks("grunt-contrib-jshint"); |
||||
grunt.loadNpmTasks("grunt-contrib-less"); |
||||
grunt.loadNpmTasks("grunt-contrib-watch"); |
||||
grunt.loadNpmTasks("grunt-contrib-concat"); |
||||
grunt.loadNpmTasks("grunt-contrib-cssmin"); |
||||
grunt.loadNpmTasks("grunt-contrib-connect"); |
||||
|
||||
grunt.registerTask("default", [ |
||||
"jshint", |
||||
"less", |
||||
"concat", |
||||
"connect", |
||||
"watch" |
||||
]); |
||||
grunt.registerTask("min", ["less", "concat", "uglify", "cssmin"]); |
||||
}; |
@ -0,0 +1,276 @@
|
||||
!(function () { |
||||
var ToDoListHeader = BI.inherit(BI.Widget, { |
||||
|
||||
props: { |
||||
baseCls: "my-todolist-header" |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.horizontal_auto", |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "bi.left_right_vertical_adapt", |
||||
width: 600, |
||||
height: o.height, |
||||
items: { |
||||
left: [ |
||||
{ |
||||
el: { |
||||
type: "bi.label", |
||||
cls: "my-todolist-title", |
||||
text: "FineUI ToDoList", |
||||
height: o.height |
||||
} |
||||
} |
||||
], |
||||
right: [ |
||||
{ |
||||
el: { |
||||
type: "bi.editor", |
||||
allowBlank: true, |
||||
cls: "my-todolist-header-editor", |
||||
watermark: "添加ToDo", |
||||
width: 300, |
||||
height: 24, |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_ENTER", |
||||
action: function () { |
||||
self.fireEvent(ToDoListHeader.EVENT_ADD, this.getValue()); |
||||
this.setValue(""); |
||||
} |
||||
} |
||||
] |
||||
} |
||||
} |
||||
] |
||||
} |
||||
} |
||||
} |
||||
] |
||||
}; |
||||
} |
||||
}); |
||||
|
||||
ToDoListHeader.EVENT_ADD = "EVENT_ADD"; |
||||
|
||||
BI.shortcut("my.todolist.header", ToDoListHeader); |
||||
})();!(function () { |
||||
var List = BI.inherit(BI.Widget, { |
||||
|
||||
props: { |
||||
baseCls: "my-todolist-list", |
||||
text: "正在进行" |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "bi.vertical_adapt", |
||||
height: 40, |
||||
items: [ |
||||
{ |
||||
type: "bi.label", |
||||
cls: "my-todolist-list-text", |
||||
textAlign: "left", |
||||
text: o.text, |
||||
width: 580 |
||||
}, { |
||||
type: "bi.center_adapt", |
||||
cls: "my-todolist-list-count-container", |
||||
width: 20, |
||||
height: 20, |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "bi.label", |
||||
ref: function (_ref) { |
||||
self.count = _ref; |
||||
}, |
||||
text: "0" |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
}, { |
||||
type: "bi.button_group", |
||||
ref: function (_ref) { |
||||
self.list = _ref; |
||||
}, |
||||
layouts: [ |
||||
{ |
||||
type: "bi.vertical", |
||||
vgap: 10 |
||||
} |
||||
], |
||||
items: o.items, |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function (v) { |
||||
self.fireEvent("EVENT_CHANGE", v); |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}; |
||||
}, |
||||
|
||||
_createItems: function (items) { |
||||
return BI.createItems(items, this.options.el); |
||||
}, |
||||
|
||||
_setCount: function (count) { |
||||
this.count.setText(count); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.list.populate(this._createItems(items)); |
||||
this._setCount(items.length); |
||||
} |
||||
}); |
||||
BI.shortcut("my.todolist.list", List); |
||||
})();!(function () { |
||||
var ToDoList = BI.inherit(BI.Widget, { |
||||
|
||||
props: { |
||||
baseCls: "fine-to-do-list" |
||||
}, |
||||
|
||||
_store: function () { |
||||
return BI.Models.getModel("my.model.todolist"); |
||||
}, |
||||
|
||||
watch: { |
||||
todoList: function (items) { |
||||
this.todolist.populate(items); |
||||
}, |
||||
doneList: function (items) { |
||||
this.donelist.populate(items); |
||||
} |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.vtape", |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "my.todolist.header", |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_ADD", |
||||
action: function (v) { |
||||
self.store.addToDo(v); |
||||
} |
||||
} |
||||
], |
||||
height: 40 |
||||
}, |
||||
height: 40 |
||||
}, { |
||||
type: "bi.horizontal_auto", |
||||
cls: "bi-background", |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "my.todolist.list", |
||||
ref: function (_ref) { |
||||
self.todolist = _ref; |
||||
}, |
||||
text: "正在进行", |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function (v) { |
||||
self.store.finish(v); |
||||
} |
||||
} |
||||
], |
||||
width: 600 |
||||
} |
||||
}, { |
||||
el: { |
||||
type: "my.todolist.list", |
||||
text: "已经完成", |
||||
ref: function (_ref) { |
||||
self.donelist = _ref; |
||||
}, |
||||
width: 600 |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("my.todolist", ToDoList); |
||||
})(); |
||||
!(function () { |
||||
|
||||
var ToDoListModel = BI.inherit(Fix.Model, { |
||||
|
||||
state: function () { |
||||
return { |
||||
list: [] |
||||
}; |
||||
}, |
||||
watch: {}, |
||||
|
||||
computed: { |
||||
todoList: function () { |
||||
var items = BI.filter(this.model.list, function (index, item) { |
||||
return !item.done; |
||||
}); |
||||
return BI.map(items, function (index, item) { |
||||
return BI.extend({ |
||||
type: "bi.multi_select_item" |
||||
}, item); |
||||
}); |
||||
}, |
||||
doneList: function () { |
||||
var items = BI.filter(this.model.list, function (index, item) { |
||||
return item.done; |
||||
}); |
||||
return BI.map(items, function (index, item) { |
||||
return BI.extend({ |
||||
type: "bi.multi_select_item", |
||||
selected: true, |
||||
disabled: true |
||||
}, item); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
actions: { |
||||
addToDo: function (v) { |
||||
this.model.list.push({ |
||||
value: BI.UUID(), |
||||
text: v, |
||||
done: false |
||||
}); |
||||
}, |
||||
|
||||
finish: function (v) { |
||||
BI.some(this.model.list, function (index, item) { |
||||
if (item.value === v) { |
||||
item.done = true; |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
}); |
||||
BI.model("my.model.todolist", ToDoListModel); |
||||
})(); |
After Width: | Height: | Size: 215 KiB |
After Width: | Height: | Size: 461 B |
After Width: | Height: | Size: 45 B |
After Width: | Height: | Size: 652 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 232 B |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 302 B |
After Width: | Height: | Size: 196 B |
After Width: | Height: | Size: 303 B |
After Width: | Height: | Size: 198 B |
After Width: | Height: | Size: 160 B |
After Width: | Height: | Size: 203 B |
After Width: | Height: | Size: 206 B |
After Width: | Height: | Size: 191 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 183 B |
After Width: | Height: | Size: 192 B |
After Width: | Height: | Size: 178 B |
After Width: | Height: | Size: 112 B |
After Width: | Height: | Size: 156 B |
After Width: | Height: | Size: 161 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 140 B |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 203 B |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 200 B |
After Width: | Height: | Size: 199 B |
After Width: | Height: | Size: 296 B |
After Width: | Height: | Size: 361 B |
After Width: | Height: | Size: 319 B |
After Width: | Height: | Size: 357 B |
After Width: | Height: | Size: 416 B |
After Width: | Height: | Size: 289 B |
After Width: | Height: | Size: 425 B |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 165 B |
After Width: | Height: | Size: 205 B |
After Width: | Height: | Size: 204 B |
After Width: | Height: | Size: 192 B |
After Width: | Height: | Size: 151 B |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 185 B |
After Width: | Height: | Size: 172 B |
After Width: | Height: | Size: 112 B |
After Width: | Height: | Size: 156 B |
After Width: | Height: | Size: 161 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 140 B |
After Width: | Height: | Size: 1007 B |
After Width: | Height: | Size: 45 B |
After Width: | Height: | Size: 652 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 342 B |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 359 B |
After Width: | Height: | Size: 209 B |
After Width: | Height: | Size: 368 B |
After Width: | Height: | Size: 209 B |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 250 B |
After Width: | Height: | Size: 254 B |
After Width: | Height: | Size: 242 B |
After Width: | Height: | Size: 192 B |
After Width: | Height: | Size: 232 B |
After Width: | Height: | Size: 240 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 127 B |
After Width: | Height: | Size: 204 B |
After Width: | Height: | Size: 200 B |
After Width: | Height: | Size: 192 B |
After Width: | Height: | Size: 183 B |
After Width: | Height: | Size: 135 B |
After Width: | Height: | Size: 224 B |
After Width: | Height: | Size: 288 B |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 249 B |
After Width: | Height: | Size: 209 B |
After Width: | Height: | Size: 400 B |
After Width: | Height: | Size: 488 B |
After Width: | Height: | Size: 426 B |
After Width: | Height: | Size: 482 B |
After Width: | Height: | Size: 497 B |
After Width: | Height: | Size: 289 B |
After Width: | Height: | Size: 410 B |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 215 B |
After Width: | Height: | Size: 265 B |
After Width: | Height: | Size: 258 B |
After Width: | Height: | Size: 244 B |