Skip to content

Commit 8c576a1

Browse files
author
HeLinJiang
committed
Merge pull request #1 from helinjiang/thinkjs
加入thinkjs框架
2 parents 6f08dd8 + 1c38367 commit 8c576a1

1,463 files changed

Lines changed: 77090 additions & 1044 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ node_modules
3939

4040
*.tmp
4141
*.temp
42+
/temp
4243

43-
npm-debug.log
44+
# IDE config
45+
.idea
4446

45-
/temp
46-
/output
47+
# output
48+
output/
49+
output.tar.gz
50+
51+
# thinkjs
52+
app/
53+
runtime/

.thinkjsrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"createAt": "2016-02-16 11:06:46",
3+
"mode": "module",
4+
"es": true
5+
}

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,25 @@ fis.match('**/*.scss', {
111111

112112
- [fis-vuejs-seed](https://github.com/zhangtao07/fis-vuejs-seed)
113113

114+
115+
116+
## thinkjs 的命令
117+
### install dependencies
118+
119+
```
120+
npm install
121+
```
122+
123+
### start server
124+
125+
```
126+
npm start
127+
```
128+
129+
### deploy with pm2
130+
131+
use pm2 to deploy app on production envrioment.
132+
133+
```
134+
pm2 startOrReload pm2.json
135+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="addpage">
2+
<button class="btn btn-success" v-on:click="showModal">
3+
新增 <i class="fa fa-plus"></i>
4+
</button>
5+
<modal title="新增用户信息" v-on:confirm="saveSubmit">
6+
<he-form action="/admin/car/save" horizontal noactions>
7+
<he-form-item title="汽车名" horizontal>
8+
<input type="text" name="name">
9+
</he-form-item>
10+
<he-form-item title="车主人" horizontal>
11+
<select2 name="ownerId" url="/admin/user/getdata" convert="searchuser" v-on:select2change="checkOwnerId" lazy v-ref:user></select2>
12+
</he-form-item>
13+
<he-form-item title="状态" horizontal>
14+
<select2 name="state" value="1">
15+
<select2-option title="有效" value="1"></select2-option>
16+
<select2-option title="无效" value="-1"></select2-option>
17+
</select2>
18+
</he-form-item>
19+
<he-form-item title="购买日期" horizontal>
20+
<date name="buydate" value="2015-12-12"></date>
21+
</he-form-item>
22+
</he-form>
23+
</modal>
24+
</div>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var Vue = require('lib/vue');
2+
3+
var validator = require('common/validator');
4+
var Msg = require('/modules/widget/msg/main');
5+
6+
module.exports = Vue.extend({
7+
template: __inline('main.html'),
8+
data: function() {
9+
return {
10+
jqForm: undefined
11+
};
12+
},
13+
methods: {
14+
showModal: function() {
15+
this._reset();
16+
this.$refs.user.init();
17+
18+
this.$children[0].show();
19+
},
20+
hideModal: function() {
21+
this.$children[0].hide();
22+
},
23+
reportSuccess: function(data) {
24+
this.$dispatch('savesuccess', data);
25+
},
26+
saveSubmit: function(msg) {
27+
// 提交表单
28+
this.jqForm.submit();
29+
},
30+
checkOwnerId: function(name) {
31+
this.jqForm.valid();
32+
},
33+
_reset: function() {
34+
// TODO select2 的初始化
35+
$('[name="name"]', this.jqForm).val('');
36+
}
37+
},
38+
ready: function() {
39+
// 缓存该值,避免重复获取
40+
this.$set('jqForm', $('form', $(this.$el)));
41+
42+
_init(this);
43+
}
44+
});
45+
46+
function _init(vm) {
47+
$(function() {
48+
handleValidator(vm);
49+
});
50+
}
51+
52+
53+
function handleValidator(vm) {
54+
validator.check(vm.jqForm, {
55+
name: {
56+
required: {
57+
rule: true,
58+
message: '汽车名字不能为空!'
59+
}
60+
},
61+
ownerId: {
62+
required: {
63+
rule: true,
64+
message: '车主人不能为空!'
65+
}
66+
}
67+
}, {
68+
submitHandler: function(form) {
69+
$(form).ajaxSubmit({
70+
success: function(responseText, statusText) {
71+
if (statusText !== 'success' || responseText.errno !== 0) {
72+
// 提示失败
73+
Msg.error('保存' + JSON.stringify(responseText.data) + '出错!');
74+
} else {
75+
// 提示成功
76+
Msg.success('保存' + JSON.stringify(responseText.data) + '成功!');
77+
78+
// 关闭对话框
79+
vm.hideModal();
80+
81+
// 刷新列表
82+
vm.reportSuccess(responseText.data);
83+
}
84+
}
85+
});
86+
}
87+
});
88+
}
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="deletepage">
2+
<modal title="删除用户信息" v-on:confirm="saveSubmit">
3+
<div class="alert alert-warning alert-dismissable">
4+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
5+
<strong>Warning!</strong> 请确定是否删除,一旦删除,数据将无法恢复!
6+
</div>
7+
<table class="table table-bordered">
8+
<tr v-for="item in items">
9+
<th>{{ item.title}}</th>
10+
<td>{{ item.value}}</td>
11+
</tr>
12+
</table>
13+
</modal>
14+
</div>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var Vue = require('lib/vue');
2+
3+
var validator = require('common/validator');
4+
var Msg = require('/modules/widget/msg/main');
5+
6+
module.exports = Vue.extend({
7+
template: __inline('main.html'),
8+
data: function() {
9+
return {
10+
id: undefined,
11+
items: []
12+
};
13+
},
14+
methods: {
15+
showModal: function(data) {
16+
this.id = data.id;
17+
18+
this.items = [{
19+
key: 'id',
20+
value: data.id,
21+
title: 'ID'
22+
}, {
23+
key: 'user_name',
24+
value: data.user_name,
25+
title: '车主人'
26+
}, {
27+
key: 'name',
28+
value: data.name,
29+
title: '汽车名字'
30+
}, {
31+
key: 'buydate',
32+
value: data.buydate,
33+
title: '购买日期'
34+
}, {
35+
key: 'stateShow',
36+
value: data.stateShow,
37+
title: '状态'
38+
}];
39+
40+
this.$children[0].show();
41+
},
42+
hideModal: function() {
43+
this.$children[0].hide();
44+
},
45+
reportSuccess: function(data) {
46+
this.$dispatch('savesuccess', data);
47+
},
48+
saveSubmit: function(msg) {
49+
var self = this;
50+
51+
$.post('/admin/car/delete', {
52+
id: this.id
53+
}, function(responseText, statusText) {
54+
console.log(responseText, statusText);
55+
if (statusText !== 'success' || responseText.errno !== 0) {
56+
// 提示失败
57+
Msg.error('删除' + JSON.stringify(responseText.data) + '出错!');
58+
} else {
59+
// 提示成功
60+
Msg.success('删除' + JSON.stringify(responseText.data) + '成功!');
61+
62+
// 关闭对话框
63+
self.hideModal();
64+
65+
// 刷新列表
66+
self.reportSuccess(responseText.data);
67+
}
68+
});
69+
}
70+
},
71+
ready: function() {
72+
73+
}
74+
});
File renamed without changes.

0 commit comments

Comments
 (0)