Authored by xuqi

replace hbs with webpack loader

@@ -203,58 +203,7 @@ @@ -203,58 +203,7 @@
203 {{/ shopping_cart_data}} 203 {{/ shopping_cart_data}}
204 </div> 204 </div>
205 205
206 - <script id="balance-tpl" type="text/html">  
207 - \{{#each promotion_formula_list}}  
208 - <li>  
209 - <span class="balance-title">\{{promotion}}</span>  
210 - <span class="balance-cost">\{{promotion_amount}}</span>  
211 - </li>  
212 - \{{/each}}  
213 - <li class="need-pay">  
214 - <span class="balance-title">应付金额\{{#if shipping_cost}}(含运费)\{{/if}}:</span>  
215 - <span id="balance-cost" class="balance-cost" data-cost="{{last_order_amount}}">¥<em>\{{round last_order_amount 2}}</em></span>  
216 - </li>  
217 - <li>  
218 - <span id="submit-order" class="btn submit-order">提交订单</span>  
219 - </li>  
220 - </script>  
221 -  
222 - <script id="address-list-tpl" type="text/html">  
223 - \{{#each address}}  
224 - <li class="address\{{#isY is_default}} default\{{/isY}}\{{#if focus}} focus\{{/if}}"  
225 - data-id="\{{address_id}}" data-name="\{{consignee}}" data-mobile="\{{mobile}}"  
226 - data-phone="\{{phone}}" data-areacode="\{{area_code}}" data-area="\{{area}}"" data-address="\{{address}}">  
227 - <div class="address-header"></div>  
228 - <div class="address-content">  
229 - <p class="default-or-not">  
230 - <span class="default-tag">默认地址</span>  
231 - <span class="set-default">设为默认</span>  
232 - </p>  
233 -  
234 - <p class="name-and-phone">  
235 - \{{consignee}}  
236 - <span class="phone bold">\{{mobile}}</span>  
237 - </p>  
238 -  
239 - <p class="address-area bold">\{{area}}</p>  
240 - <p class="address-detail">\{{address}}</p>  
241 -  
242 - <p class="address-opration">  
243 - <span class="modify">修改</span>  
244 - <span class="delete">删除</span>  
245 - </p>  
246 - </div>  
247 - <span class="address-chosed iconfont">&#xe63b;</span>  
248 - </li>  
249 - \{{/each}}  
250 - \{{#if hasNew}}  
251 - <li class="new-address-block">  
252 - <span class="iconfont">&#xe645;</span>  
253 - 增加收货地址  
254 - </li>  
255 - \{{/if}}  
256 - </script>  
257 - 206 + {{!-- 服务端渲染,客户端使用 --}}
258 <script id="invoice-dialog-tpl" type="text/html"> 207 <script id="invoice-dialog-tpl" type="text/html">
259 <p class="dialog-title">发票信息</p> 208 <p class="dialog-title">发票信息</p>
260 <ul class="invoice-tab"> 209 <ul class="invoice-tab">
@@ -303,101 +252,6 @@ @@ -303,101 +252,6 @@
303 </div> 252 </div>
304 </div> 253 </div>
305 </script> 254 </script>
306 -  
307 - <script id="address-dialog-tpl" type="text/html">  
308 - <p class="dialog-title">  
309 - \{{#if updateAddress}}  
310 - 修改地址  
311 - \{{^}}  
312 - 新增地址  
313 - \{{/if}}  
314 - </p>  
315 - <form id="address-form" name="address-form">  
316 - <div class="address-page">  
317 - <span class="tip">  
318 - <em class="blue">  
319 - \{{#if updateAddress}}  
320 - 修改地址  
321 - \{{^}}  
322 - 新增地址  
323 - \{{/if}}  
324 - </em>  
325 - 电话为选填项,其他均为必填项  
326 - </span>  
327 - <div class="add-address-detail" data-id="\{{id}}">  
328 - <div class="form-group">  
329 - <label class="label-name">  
330 - <em class="required-mark">*</em>  
331 - 收货人:  
332 - </label>  
333 - <input class="input address-name" type="text" placeholder="请输入您的姓名" maxlength="12" value="\{{name}}">  
334 - <span class="blue error-tips">  
335 - {{> icon/error-round}}  
336 - <em></em>  
337 - </span>  
338 - </div>  
339 - <div class="form-group clearfix">  
340 - <label class="label-name">  
341 - <em class="required-mark">*</em>  
342 - 所在区域:  
343 - </label>  
344 - <div id="address" class="clearfix"></div>  
345 - <span class="blue error-tips">  
346 - {{> icon/error-round}}  
347 - 请填写完整的省市区信息  
348 - </span>  
349 - </div>  
350 - <div class="form-group">  
351 - <label class="label-name">  
352 - <em class="required-mark">*</em>  
353 - 详细地址:  
354 - </label>  
355 - <input class="input address-detail" type="text" placeholder="街道名称或小区名称" maxlength="60" value="\{{detail}}">  
356 - <span class="blue error-tips">  
357 - {{> icon/error-round}}  
358 - <em></em>  
359 - </span>  
360 - </div>  
361 - <div class="form-group">  
362 - <label class="label-name">  
363 - <em class="required-mark">*</em>  
364 - 手机号码:  
365 - </label>  
366 - <input class="input address-mobile" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11" value="\{{mobile}}">  
367 - <span class="blue error-tips">  
368 - {{> icon/error-round}}  
369 - <em></em>  
370 - </span>  
371 - </div>  
372 - <div class="form-group">  
373 - <label class="label-name">电话号码:</label>  
374 - <input class="input address-phone" type="text" placeholder="请输入电话号码(选填)" value="\{{phone}}" maxlength="15">  
375 - <span class="blue error-tips">  
376 - {{> icon/error-round}}  
377 - <em></em>  
378 - </span>  
379 - </div>  
380 - </div>  
381 - </div>  
382 - </form>  
383 - </script>  
384 -  
385 - <script id="checked-invoice-show-tpl" type="text/html">  
386 - <div class="invoice-radio">  
387 - \{{#if checked}}  
388 - <span class="iconfont radio checked">&#xe603;</span>  
389 - \{{^}}  
390 - <span class="iconfont radio">&#xe604;</span>  
391 - \{{/if}}  
392 - <label>发票开具</label>  
393 - </div>  
394 - \{{#if invoiceTitle}}  
395 - <p class="invoice-detail" data-title="\{{invoiceTitle}}" data-content="\{{content}}">  
396 - <em>\{{invoiceTitle}}</em><em>\{{invoiceContent}}</em>  
397 - <span class="modify-invoice btn white">修改</span>  
398 - </p>  
399 - \{{/if}}  
400 - </script>  
401 </div> 255 </div>
402 {{/ content}} 256 {{/ content}}
403 </div> 257 </div>
  1 +/**
  2 + * 判断值是否是'Y'
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2016/7/27
  5 + */
  6 +
  7 +module.exports = function(value, options) {
  8 + if (value === 'Y') {
  9 + return options.fn(this);
  10 + } else {
  11 + return options.inverse(this);
  12 + }
  13 +};
  1 +/**
  2 + * 精确n位小数
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2016/7/27
  5 + */
  6 +
  7 +/**
  8 + * @param num 数字
  9 + * @param precision 精确度,默认2
  10 + */
  11 +module.exports = function(num, precision) {
  12 + precision = precision ? parseInt(precision, 10) : 2;
  13 + num = (num === +num) ? (+num).toFixed(precision) : (Math.round(num, precision)).toFixed(precision);
  14 + return num;
  15 +};
@@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
5 */ 5 */
6 6
7 var $ = require('yoho-jquery'), 7 var $ = require('yoho-jquery'),
8 - Hbs = require('yoho-handlebars'),  
9 lazyLoad = require('yoho-jquery-lazyload'); 8 lazyLoad = require('yoho-jquery-lazyload');
10 9
11 var Alert = require('../plugins/dialog').Alert; 10 var Alert = require('../plugins/dialog').Alert;
@@ -34,7 +33,7 @@ var $printPrice = $('#print-price'); @@ -34,7 +33,7 @@ var $printPrice = $('#print-price');
34 33
35 var $invoice = $('#invoice-content'); 34 var $invoice = $('#invoice-content');
36 35
37 -var balanceTpl = Hbs.compile($('#balance-tpl').html()); 36 +var balanceTpl = require('../../tpl/shopping/balance.hbs');
38 37
39 var pkgCache = {}; 38 var pkgCache = {};
40 39
@@ -47,13 +46,6 @@ require('../plugins/check'); // before 地址和发票 @@ -47,13 +46,6 @@ require('../plugins/check'); // before 地址和发票
47 require('./order/address'); // 地址 46 require('./order/address'); // 地址
48 require('./order/invoice'); // 发票 47 require('./order/invoice'); // 发票
49 48
50 -// clint helper round  
51 -Hbs.registerHelper('round', function(num, precision) {  
52 - precision = precision ? parseInt(precision, 10) : 2;  
53 - num = (num === +num) ? (+num).toFixed(precision) : (Math.round(num, precision)).toFixed(precision);  
54 - return num;  
55 -});  
56 -  
57 lazyLoad($('img.lazy')); 49 lazyLoad($('img.lazy'));
58 50
59 // dot 51 // dot
@@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
5 */ 5 */
6 6
7 var $ = require('yoho-jquery'), 7 var $ = require('yoho-jquery'),
8 - Hbs = require('yoho-handlebars'),  
9 cascadingAddress = require('../../plugins/cascading-address'), 8 cascadingAddress = require('../../plugins/cascading-address'),
10 common = require('../../common'), 9 common = require('../../common'),
11 popup = require('../../plugins/dialog'); 10 popup = require('../../plugins/dialog');
@@ -41,17 +40,8 @@ function setAllOfAddress() { @@ -41,17 +40,8 @@ function setAllOfAddress() {
41 } 40 }
42 } 41 }
43 42
44 -// 判断是否是Y  
45 -Hbs.registerHelper('isY', function(value, options) {  
46 - if (value === 'Y') {  
47 - return options.fn(this);  
48 - } else {  
49 - return options.inverse(this);  
50 - }  
51 -});  
52 -  
53 -addressDialogTpl = Hbs.compile($('#address-dialog-tpl').html());  
54 -addressTpl = Hbs.compile($('#address-list-tpl').html()); 43 +addressDialogTpl = require('../../../tpl/shopping/address-dialog.hbs');
  44 +addressTpl = require('../../../tpl/shopping/address-list.hbs');
55 45
56 // address dialog 数据验证 46 // address dialog 数据验证
57 function validateAddress($el) { 47 function validateAddress($el) {
@@ -5,10 +5,9 @@ @@ -5,10 +5,9 @@
5 */ 5 */
6 6
7 var $ = require('yoho-jquery'), 7 var $ = require('yoho-jquery'),
8 - hbs = require('yoho-handlebars'),  
9 Dialog = require('../../plugins/dialog').Dialog; 8 Dialog = require('../../plugins/dialog').Dialog;
10 9
11 -var checkedInvoiceTpl = hbs.compile($('#checked-invoice-show-tpl').html()); 10 +var checkedInvoiceTpl = require('../../../tpl/shopping/checked-invoice-show.hbs');
12 11
13 var $invoiceContent = $('#invoice-content'); 12 var $invoiceContent = $('#invoice-content');
14 13
  1 +<p class="dialog-title">
  2 + {{#if updateAddress}}
  3 + 修改地址
  4 + {{^}}
  5 + 新增地址
  6 + {{/if}}
  7 +</p>
  8 +<form id="address-form" name="address-form">
  9 + <div class="address-page">
  10 + <span class="tip">
  11 + <em class="blue">
  12 + {{#if updateAddress}}
  13 + 修改地址
  14 + {{^}}
  15 + 新增地址
  16 + {{/if}}
  17 + </em>
  18 + 电话为选填项,其他均为必填项
  19 + </span>
  20 + <div class="add-address-detail" data-id="{{id}}">
  21 + <div class="form-group">
  22 + <label class="label-name">
  23 + <em class="required-mark">*</em>
  24 + 收货人:
  25 + </label>
  26 + <input class="input address-name" type="text" placeholder="请输入您的姓名" maxlength="12" value="{{name}}">
  27 + <span class="blue error-tips">
  28 + {{> error-round}}
  29 + <em></em>
  30 + </span>
  31 + </div>
  32 + <div class="form-group clearfix">
  33 + <label class="label-name">
  34 + <em class="required-mark">*</em>
  35 + 所在区域:
  36 + </label>
  37 + <div id="address" class="clearfix"></div>
  38 + <span class="blue error-tips">
  39 + {{> error-round}}
  40 + 请填写完整的省市区信息
  41 + </span>
  42 + </div>
  43 + <div class="form-group">
  44 + <label class="label-name">
  45 + <em class="required-mark">*</em>
  46 + 详细地址:
  47 + </label>
  48 + <input class="input address-detail" type="text" placeholder="街道名称或小区名称" maxlength="60" value="{{detail}}">
  49 + <span class="blue error-tips">
  50 + {{> error-round}}
  51 + <em></em>
  52 + </span>
  53 + </div>
  54 + <div class="form-group">
  55 + <label class="label-name">
  56 + <em class="required-mark">*</em>
  57 + 手机号码:
  58 + </label>
  59 + <input class="input address-mobile" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11" value="{{mobile}}">
  60 + <span class="blue error-tips">
  61 + {{> error-round}}
  62 + <em></em>
  63 + </span>
  64 + </div>
  65 + <div class="form-group">
  66 + <label class="label-name">电话号码:</label>
  67 + <input class="input address-phone" type="text" placeholder="请输入电话号码(选填)" value="{{phone}}" maxlength="15">
  68 + <span class="blue error-tips">
  69 + {{> error-round}}
  70 + <em></em>
  71 + </span>
  72 + </div>
  73 + </div>
  74 + </div>
  75 +</form>
  1 +{{#each address}}
  2 + <li class="address{{#isY is_default}} default{{/isY}}{{#if focus}} focus{{/if}}"
  3 + data-id="{{address_id}}" data-name="{{consignee}}" data-mobile="{{mobile}}"
  4 + data-phone="{{phone}}" data-areacode="{{area_code}}" data-area="{{area}}"" data-address="{{address}}">
  5 + <div class="address-header"></div>
  6 + <div class="address-content">
  7 + <p class="default-or-not">
  8 + <span class="default-tag">默认地址</span>
  9 + <span class="set-default">设为默认</span>
  10 + </p>
  11 +
  12 + <p class="name-and-phone">
  13 + {{consignee}}
  14 + <span class="phone bold">{{mobile}}</span>
  15 + </p>
  16 +
  17 + <p class="address-area bold">{{area}}</p>
  18 + <p class="address-detail">{{address}}</p>
  19 +
  20 + <p class="address-opration">
  21 + <span class="modify">修改</span>
  22 + <span class="delete">删除</span>
  23 + </p>
  24 + </div>
  25 + <span class="address-chosed iconfont">&#xe63b;</span>
  26 + </li>
  27 +{{/each}}
  28 +{{#if hasNew}}
  29 + <li class="new-address-block">
  30 + <span class="iconfont">&#xe645;</span>
  31 + 增加收货地址
  32 + </li>
  33 +{{/if}}
  1 +{{#each promotion_formula_list}}
  2 + <li>
  3 + <span class="balance-title">{{promotion}}</span>
  4 + <span class="balance-cost">{{promotion_amount}}</span>
  5 + </li>
  6 +{{/each}}
  7 +<li class="need-pay">
  8 + <span class="balance-title">应付金额{{#if shipping_cost}}(含运费){{/if}}</span>
  9 + <span id="balance-cost" class="balance-cost" data-cost="{{last_order_amount}}">¥<em>{{round last_order_amount 2}}</em></span>
  10 +</li>
  11 +<li>
  12 + <span id="submit-order" class="btn submit-order">提交订单</span>
  13 +</li>
  1 +<div class="invoice-radio">
  2 + {{#if checked}}
  3 + <span class="iconfont radio checked">&#xe603;</span>
  4 + {{^}}
  5 + <span class="iconfont radio">&#xe604;</span>
  6 + {{/if}}
  7 + <label>发票开具</label>
  8 +</div>
  9 +{{#if invoiceTitle}}
  10 + <p class="invoice-detail" data-title="{{invoiceTitle}}" data-content="{{content}}">
  11 + <em>{{invoiceTitle}}</em><em>{{invoiceContent}}</em>
  12 + <span class="modify-invoice btn white">修改</span>
  13 + </p>
  14 +{{/if}}
  1 +<span class="iconfont">&#xe60c;</span>
@@ -39,7 +39,7 @@ module.exports = { @@ -39,7 +39,7 @@ module.exports = {
39 loaders: [ 39 loaders: [
40 { 40 {
41 test: /\.hbs$/, 41 test: /\.hbs$/,
42 - loader: 'handlebars-loader' 42 + loader: `handlebars-loader?helperDirs[]=${__dirname}/helper`
43 } 43 }
44 ] 44 ]
45 }, 45 },