[控件]unigui移动端下Unidatepicker时间显示解决方案

http://tz10000.com/kong-jian-unigui-yi-dong-duan-xia-unidatepicker-shi-jian-xian-shi-jie-jue-fang-an.html

2017-03-07 • Delphi • 评论关闭 • Aar0n

unigui搞移动端,需求上需要采用日期,但是默认是不支持时间选择的,怎么办?

只能改造了@~@。

1.下载以下JS文件放到程序files目录下。

  1. https://raw.githubusercontent.com/tomalex0/senchatouch-datetimepickerv2/master/ux/DateTime.js
  2. https://raw.githubusercontent.com/tomalex0/senchatouch-datetimepickerv2/master/ux/DateTimePicker.js

2.在CustomFiles项目加入如下内容。

  1. files/DateTime.js
  2. files/DateTimePicker.js

3.调整时间格式,如下。

  1. UnimDatePicker1.DateFormat := "dd/MM/yyyy H:i"

4.对控件添加以下事件。

1. UnimDatePicker1 -> ClientEvents -> UniEvents .. beforeInit fn:

  1. function beforeInit(sender, config)
  2. {
  3.     config.picker = Ext.create('Ext.ux.picker.DateTime', {
  4.                     useTitles: false,
  5.                     doneButton: true,
  6.                     cancelButton: true,
  7.                     minuteInterval : 1,
  8.                     //slotOrder: ['month', 'day', 'year','hour','minute'],
  9.                     toolbar: {
  10.                       //items : datetimepickettoolbaritems
  11.                     }                        
  12.                   });
  13.     Ext.Date.patterns={CustomFormat: "d/m/Y H:i"}; // <------------
  14. }

2. UnimDatePicker1 -> ClientEvents -> ExtEvents -> function change:

  1. function change(sender, newDate, oldDate, eOpts)
  2. {
  3.     ajaxRequest(sender, '_dateChange', ['val='+Ext.Date.format(newDate, Ext.Date.patterns.CustomFormat)])
  4. }

3. UnimDatePicker1 -> OnAjaxEvent:

  1. procedure TMainmForm.UnimDatePicker1AjaxEvent(Sender: TComponent;
  2.   EventName: string; Params: TUniStrings);
  3. var
  4.   newDateTime : TDateTime;
  5.   Fmt: TFormatSettings;
  6. begin
  7.   if EventName = '_dateChange' then
  8.   begin
  9.     Fmt.ShortDateFormat:='dd/mm/yyyy';
  10.     Fmt.DateSeparator  :='/';
  11.     Fmt.LongTimeFormat :='hh:mm';
  12.     Fmt.TimeSeparator  :=':';
  13.    
  14.     newDateTime := StrToDateTime(Params.Values['val'], Fmt);
  15.     //ShowMessage(DateTimeToStr(newDateTime));
  16.   end;
  17.  
  18. end;
  1. https://raw.githubusercontent.com/tomalex0/senchatouch-datetimepickerv2/master/ux/DateTime.js
  1.  
  2. Ext.define('Ext.ux.picker.DateTime', {
  3. extend: 'Ext.picker.Picker',
  4. xtype: 'datetimepicker',
  5. alternateClassName: 'Ext.ux.DateTimePicker',
  6. requires: ['Ext.DateExtras'],
  7.  
  8. config: {
  9. /**
  10. * @cfg {Number} yearFrom
  11. * The start year for the date picker.
  12. * @accessor
  13. */
  14. yearFrom: 1980,
  15.  
  16. /**
  17. * @cfg {Number} yearTo
  18. * The last year for the date picker.
  19. * @default the current year (new Date().getFullYear())
  20. * @accessor
  21. */
  22. yearTo: new Date().getFullYear(),
  23.  
  24. /**
  25. * @cfg {String} monthText
  26. * The label to show for the month column.
  27. * @accessor
  28. */
  29. monthText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'M' : 'Month',
  30.  
  31. /**
  32. * @cfg {String} dayText
  33. * The label to show for the day column.
  34. * @accessor
  35. */
  36. dayText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'j' : 'Day',
  37.  
  38. /**
  39. * @cfg {String} yearText
  40. * The label to show for the year column.
  41. * @accessor
  42. */
  43. yearText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'Y' : 'Year',
  44.  
  45. /**
  46. * @cfg {String} hourText
  47. * The label to show for the hour column. Defaults to 'Hour'.
  48. */
  49. hourText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'H' : 'Hour',
  50.  
  51. /**
  52. * @cfg {String} minuteText
  53. * The label to show for the minute column. Defaults to 'Minute'.
  54. */
  55. minuteText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'i' : 'Minute',
  56.  
  57. /**
  58. * @cfg {String} ampmText
  59. * The label to show for the ampm column. Defaults to 'AM/PM'.
  60. */
  61. ampmText: (Ext.os.deviceType.toLowerCase() == "phone") ? 'A' : 'AM/PM',
  62.  
  63. /**
  64. * @cfg {Array} slotOrder
  65. * An array of strings that specifies the order of the slots.
  66. * @accessor
  67. */
  68. slotOrder: ['month', 'day', 'year','hour','minute','ampm'],
  69.  
  70. /**
  71. * @cfg {Int} minuteInterval
  72. * @accessor
  73. */
  74. minuteInterval : 15,
  75.  
  76. /**
  77. * @cfg {Boolean} ampm
  78. * @accessor
  79. */
  80. ampm : false,
  81.  
  82. /**
  83. * @cfg {Boolean} displayUTC
  84. * If set to true, displays UTC time in the DatePicker
  85. * @accessor
  86. */
  87. displayUTC: false
  88. },
  89.  
  90. initialize: function() {
  91. this.callParent();
  92.  
  93. this.on({
  94. scope: this,
  95. delegate: '> slot',
  96. slotpick: this.onSlotPick
  97. });
  98. },
  99.  
  100. setValue: function(value, animated) {
  101. if (Ext.isDate(value)) {
  102.  
  103. // See if we should display in UTC
  104. if (this.getDisplayUTC()) {
  105. ampm = 'AM';
  106. currentHours = hour = value.getUTCHours();
  107. if(this.getAmpm()){
  108. if (currentHours > 12) {
  109. ampm = "PM";
  110. hour -= 12;
  111. } else if(currentHours == 12) {
  112. ampm = "PM";
  113. } else if(currentHours == 0) {
  114. hour = 12;
  115. }
  116. }
  117. value = {
  118. day : value.getUTCDate(),
  119. month: value.getUTCMonth() + 1,
  120. year : value.getUTCFullYear(),
  121. hour : hour,
  122. minute : value.getUTCMinutes(),
  123. ampm : ampm
  124. };
  125. // Display in local timezone
  126. } else {
  127. ampm = 'AM';
  128. currentHours = hour = value.getHours();
  129. if(this.getAmpm()){
  130. if (currentHours > 12) {
  131. ampm = "PM";
  132. hour -= 12;
  133. } else if(currentHours == 12) {
  134. ampm = "PM";
  135. } else if(currentHours == 0) {
  136. hour = 12;
  137. }
  138. }
  139. value = {
  140. day : value.getDate(),
  141. month: value.getMonth() + 1,
  142. year : value.getFullYear(),
  143. hour : hour,
  144. minute : value.getMinutes(),
  145. ampm : ampm
  146. };
  147. }
  148. }
  149.  
  150. this.callParent([value, animated]);
  151. },
  152.  
  153. getValue: function() {
  154. var values = {},
  155. daysInMonth, day, hour, minute,
  156. items = this.getItems().items,
  157. ln = items.length,
  158. item, i;
  159.  
  160. for (i = 0; i < ln; i++) {
  161. item = items[i];
  162. if (item instanceof Ext.picker.Slot) {
  163. values[item.getName()] = item.getValue(true);
  164. }
  165. }
  166. daysInMonth = this.getDaysInMonth(values.month, values.year);
  167. day = Math.min(values.day, daysInMonth),hour = values.hour, minute = values.minute;
  168.  
  169. var yearval = (isNaN(values.year)) ? new Date().getFullYear() : values.year,
  170. monthval = (isNaN(values.month)) ? (new Date().getMonth()) : (values.month - 1),
  171. dayval = (isNaN(day)) ? (new Date().getDate()) : day,
  172. hourval = (isNaN(hour)) ? new Date().getHours() : hour,
  173. minuteval = (isNaN(minute)) ? new Date().getMinutes() : minute;
  174. if(values.ampm && values.ampm == "PM" && hourval<12){
  175. hourval = hourval + 12;
  176. }
  177. if(values.ampm && values.ampm == "AM" && hourval == 12){
  178. hourval = 0;
  179. }
  180.  
  181. // Return the proper values based upon UTC
  182. if (this.getDisplayUTC()) {
  183. return new Date(Date.UTC(yearval, monthval, dayval, hourval, minuteval));
  184. } else {
  185. return new Date(yearval, monthval, dayval, hourval, minuteval);
  186. }
  187. },
  188.  
  189. /**
  190. * Updates the yearFrom configuration
  191. */
  192. updateYearFrom: function() {
  193. if (this.initialized) {
  194. this.createSlots();
  195. }
  196. },
  197.  
  198. /**
  199. * Updates the yearTo configuration
  200. */
  201. updateYearTo: function() {
  202. if (this.initialized) {
  203. this.createSlots();
  204. }
  205. },
  206.  
  207. /**
  208. * Updates the monthText configuration
  209. */
  210. updateMonthText: function(newMonthText, oldMonthText) {
  211. var innerItems = this.getInnerItems,
  212. ln = innerItems.length,
  213. item, i;
  214.  
  215. //loop through each of the current items and set the title on the correct slice
  216. if (this.initialized) {
  217. for (i = 0; i < ln; i++) {
  218. item = innerItems[i];
  219.  
  220. if ((typeof item.title == "string" && item.title == oldMonthText) || (item.title.html == oldMonthText)) {
  221. item.setTitle(newMonthText);
  222. }
  223. }
  224. }
  225. },
  226.  
  227. /**
  228. * Updates the dayText configuraton
  229. */
  230. updateDayText: function(newDayText, oldDayText) {
  231. var innerItems = this.getInnerItems,
  232. ln = innerItems.length,
  233. item, i;
  234.  
  235. //loop through each of the current items and set the title on the correct slice
  236. if (this.initialized) {
  237. for (i = 0; i < ln; i++) {
  238. item = innerItems[i];
  239.  
  240. if ((typeof item.title == "string" && item.title == oldDayText) || (item.title.html == oldDayText)) {
  241. item.setTitle(newDayText);
  242. }
  243. }
  244. }
  245. },
  246.  
  247. /**
  248. * Updates the yearText configuration
  249. */
  250. updateYearText: function(yearText) {
  251. var innerItems = this.getInnerItems,
  252. ln = innerItems.length,
  253. item, i;
  254.  
  255. //loop through each of the current items and set the title on the correct slice
  256. if (this.initialized) {
  257. for (i = 0; i < ln; i++) {
  258. item = innerItems[i];
  259.  
  260. if (item.title == this.yearText) {
  261. item.setTitle(yearText);
  262. }
  263. }
  264. }
  265. },
  266.  
  267. // @private
  268. constructor: function() {
  269. this.callParent(arguments);
  270. this.createSlots();
  271. },
  272.  
  273. /**
  274. * Generates all slots for all years specified by this component, and then sets them on the component
  275. * @private
  276. */
  277. createSlots: function() {
  278. var me = this,
  279. slotOrder = this.getSlotOrder(),
  280. yearsFrom = me.getYearFrom(),
  281. yearsTo = me.getYearTo(),
  282. years = [],
  283. days = [],
  284. months = [],
  285. hours = [],
  286. minutes = [],
  287. ampm= [],
  288. ln, tmp, i,
  289. daysInMonth;
  290.  
  291. if(!this.getAmpm()){
  292. var index = slotOrder.indexOf('ampm');
  293. if(index >= 0){
  294. slotOrder.splice(index);
  295. }
  296. }
  297. // swap values if user mixes them up.
  298. if (yearsFrom > yearsTo) {
  299. tmp = yearsFrom;
  300. yearsFrom = yearsTo;
  301. yearsTo = tmp;
  302. }
  303.  
  304. for (i = yearsFrom; i <= yearsTo; i++) {
  305. years.push({
  306. text: i,
  307. value: i
  308. });
  309. }
  310.  
  311. daysInMonth = this.getDaysInMonth(1, new Date().getFullYear());
  312.  
  313. for (i = 0; i < daysInMonth; i++) {
  314. days.push({
  315. text: i + 1,
  316. value: i + 1
  317. });
  318. }
  319.  
  320. for (i = 0, ln = Ext.Date.monthNames.length; i < ln; i++) {
  321. months.push({
  322. text: (Ext.os.deviceType.toLowerCase() == "phone") ? Ext.Date.monthNames[i].substring(0,3) : Ext.Date.monthNames[i],
  323. value: i + 1
  324. });
  325. }
  326.  
  327. var hourLimit = (this.getAmpm()) ? 12 : 23;
  328. var hourStart = (this.getAmpm()) ? 1 : 0;
  329. for(i=hourStart;i<=hourLimit;i++){
  330. hours.push({
  331. text: this.pad2(i),
  332. value: i
  333. });
  334. }
  335.  
  336. for(i=0;i<60;i+=this.getMinuteInterval()){
  337. minutes.push({
  338. text: this.pad2(i),
  339. value: i
  340. });
  341. }
  342.  
  343. ampm.push({
  344. text: 'AM',
  345. value: 'AM'
  346. },{
  347. text: 'PM',
  348. value: 'PM'
  349. });
  350.  
  351. var slots = [];
  352.  
  353. slotOrder.forEach(function(item) {
  354. slots.push(this.createSlot(item, days, months, years,hours,minutes,ampm));
  355. }, this);
  356.  
  357. me.setSlots(slots);
  358. },
  359.  
  360. /**
  361. * Returns a slot config for a specified date.
  362. * @private
  363. */
  364. createSlot: function(name, days, months, years,hours,minutes,ampm) {
  365. var isPhone = (Ext.os.deviceType.toLowerCase() == "phone"),
  366. align = (isPhone) ? 'left' : 'center';
  367.  
  368. switch (name) {
  369. case 'year':
  370. return {
  371. name: 'year',
  372. align: align,
  373. data: years,
  374. title: this.getYearText(),
  375. flex: isPhone ? 1.3 : 3
  376. };
  377. case 'month':
  378. return {
  379. name: name,
  380. align: isPhone ? 'left' : 'right',
  381. data: months,
  382. title: this.getMonthText(),
  383. flex: isPhone ? 1.2 : 4
  384. };
  385. case 'day':
  386. return {
  387. name: 'day',
  388. align: align,
  389. data: days,
  390. title: this.getDayText(),
  391. flex: isPhone ? 0.9 : 2
  392. };
  393. case 'hour':
  394. return {
  395. name: 'hour',
  396. align: align,
  397. data: hours,
  398. title: this.getHourText(),
  399. flex: isPhone ? 0.9 : 2
  400. };
  401. case 'minute':
  402. return {
  403. name: 'minute',
  404. align: align,
  405. data: minutes,
  406. title: this.getMinuteText(),
  407. flex: isPhone ? 0.9 : 2
  408. };
  409. case 'ampm':
  410. return {
  411. name: 'ampm',
  412. align: align,
  413. data: ampm,
  414. title: this.getAmpmText(),
  415. flex: isPhone ? 1.1 : 2
  416. };
  417. }
  418. },
  419.  
  420. onSlotPick: function(pickedSlot, oldValue, htmlNode, eOpts) {
  421.  
  422. // We don't actually get passed the new value. I think this is an ST2 bug. Instead we get passed the slot,
  423. // the oldValue, the node in the slot which was moved to, and options for the event.
  424. //
  425. // However looking at the code that fires the slotpick event, the slot.selectedIndex is always set there
  426. // We can therefore use this to pull the underlying value that was picked out of the slot's store
  427. var pickedValue = pickedSlot.getStore().getAt(pickedSlot.selectedIndex).get(pickedSlot.getValueField());
  428.  
  429. pickedSlot.setValue(pickedValue);
  430.  
  431. if(pickedSlot.getName() === 'month' || pickedSlot.getName() === 'year') {
  432. this.repopulateDaySlot();
  433. }
  434. },
  435.  
  436. repopulateDaySlot: function() {
  437. var slot = this.getDaySlot(),
  438. days = [],
  439. month = this.getSlotByName('month').getValue(),
  440. year = this.getSlotByName('year').getValue(),
  441. daysInMonth;
  442.  
  443. // Get the new days of the month for this new date
  444. daysInMonth = this.getDaysInMonth(month, year);
  445.  
  446. for (var i = 0; i < daysInMonth; i++) {
  447. days.push({
  448. text: i + 1,
  449. value: i + 1
  450. });
  451. }
  452.  
  453. // We dont need to update the slot days unless it has changed
  454. if (slot.getData().length == days.length) {
  455. return;
  456. }
  457.  
  458. slot.setData(days);
  459. },
  460.  
  461. getSlotByName: function(name) {
  462. return this.down('pickerslot[name=' + name + ']');
  463. },
  464.  
  465. getDaySlot: function() {
  466. return this.getSlotByName('day');
  467. },
  468.  
  469. // @private
  470. getDaysInMonth: function(month, year) {
  471. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  472. return month == 2 && this.isLeapYear(year) ? 29 : daysInMonth[month-1];
  473. },
  474.  
  475. // @private
  476. isLeapYear: function(year) {
  477. return !!((year & 3) === 0 && (year % 100 || (year % 400 === 0 && year)));
  478. },
  479. pad2 : function(number) {
  480. return (number < 10 ? '0' : '') + number ;
  481. }
  482. });
  1. https://raw.githubusercontent.com/tomalex0/senchatouch-datetimepickerv2/master/ux/DateTimePicker.js
  1. /**
  2. * @aside guide forms
  3. *
  4. * This is a specialized field which shows a {@link Ext.ux.picker.DateTime} when tapped. If it has a predefined value,
  5. * or a value is selected in the {@link Ext.ux.picker.DateTime}, it will be displayed like a normal {@link Ext.field.Text}
  6. * (but not selectable/changable).
  7. *
  8. * Ext.create('Ext.ux.field.DateTimePicker', {
  9. * label: 'Birthday',
  10. * value: new Date()
  11. * });
  12. *
  13. * {@link Ext.ux.field.DateTimePicker} fields are very simple to implement, and have no required configurations.
  14. *
  15. * ## Examples
  16. *
  17. * It can be very useful to set a default {@link #value} configuration on {@link Ext.ux.field.DateTimePicker} fields. In
  18. * this example, we set the {@link #value} to be the current date. You can also use the {@link #setValue} method to
  19. * update the value at any time.
  20. *
  21. * @example miniphone preview
  22. * Ext.create('Ext.form.Panel', {
  23. * fullscreen: true,
  24. * items: [
  25. * {
  26. * xtype: 'fieldset',
  27. * items: [
  28. * {
  29. * xtype: 'datetimepickerfield',
  30. * label: 'Birthday',
  31. * name: 'birthday',
  32. * value: new Date()
  33. * }
  34. * ]
  35. * },
  36. * {
  37. * xtype: 'toolbar',
  38. * docked: 'bottom',
  39. * items: [
  40. * { xtype: 'spacer' },
  41. * {
  42. * text: 'setValue',
  43. * handler: function() {
  44. * var datetimepickerfield = Ext.ComponentQuery.query('datetimepickerfield')[0];
  45. *
  46. * var randomNumber = function(from, to) {
  47. * return Math.floor(Math.random() * (to - from + 1) + from);
  48. * };
  49. *
  50. * datetimepickerfield.setValue({
  51. * month: randomNumber(0, 11),
  52. * day : randomNumber(0, 28),
  53. * year : randomNumber(1980, 2011)
  54. * });
  55. * }
  56. * },
  57. * { xtype: 'spacer' }
  58. * ]
  59. * }
  60. * ]
  61. * });
  62. *
  63. * When you need to retrieve the date from the {@link Ext.ux.field.DateTimePicker}, you can either use the {@link #getValue} or
  64. * {@link #getFormattedValue} methods:
  65. *
  66. * @example preview
  67. * Ext.create('Ext.form.Panel', {
  68. * fullscreen: true,
  69. * items: [
  70. * {
  71. * xtype: 'fieldset',
  72. * items: [
  73. * {
  74. * xtype: 'datetimepickerfield',
  75. * label: 'Birthday',
  76. * name: 'birthday',
  77. * value: new Date()
  78. * }
  79. * ]
  80. * },
  81. * {
  82. * xtype: 'toolbar',
  83. * docked: 'bottom',
  84. * items: [
  85. * {
  86. * text: 'getValue',
  87. * handler: function() {
  88. * var datetimepickerfield = Ext.ComponentQuery.query('datetimepickerfield')[0];
  89. * Ext.Msg.alert(null, datetimepickerfield.getValue());
  90. * }
  91. * },
  92. * { xtype: 'spacer' },
  93. * {
  94. * text: 'getFormattedValue',
  95. * handler: function() {
  96. * var datetimepickerfield = Ext.ComponentQuery.query('datetimepickerfield')[0];
  97. * Ext.Msg.alert(null, datetimepickerfield.getFormattedValue());
  98. * }
  99. * }
  100. * ]
  101. * }
  102. * ]
  103. * });
  104. *
  105. *
  106. */
  107.  
  108. Ext.define('Ext.ux.field.DateTimePicker', {
  109. extend: 'Ext.field.Text',
  110. alternateClassName: 'Ext.form.DateTimePicker',
  111. xtype: 'datetimepickerfield',
  112. requires: [
  113. 'Ext.ux.picker.DateTime',
  114. 'Ext.DateExtras'
  115. ],
  116.  
  117. /**
  118. * @event change
  119. * Fires when a date is selected
  120. * @param {Ext.ux.field.DateTimePicker} this
  121. * @param {Date} date The new date
  122. */
  123.  
  124. config: {
  125. ui: 'select',
  126.  
  127. /**
  128. * @cfg {Object/Ext.ux.picker.DateTime} picker
  129. * An object that is used when creating the internal {@link Ext.ux.picker.DateTime} component or a direct instance of {@link Ext.ux.picker.DateTime}
  130. * Defaults to true
  131. * @accessor
  132. */
  133. picker: true,
  134.  
  135. /**
  136. * @cfg {Boolean}
  137. * @hide
  138. * @accessor
  139. */
  140. clearIcon: false,
  141.  
  142. /**
  143. * @cfg {Object/Date} value
  144. * Default value for the field and the internal {@link Ext.ux.picker.DateTime} component. Accepts an object of 'year',
  145. * 'month' and 'day' values, all of which should be numbers, or a {@link Date}.
  146. *
  147. * Example: {year: 1989, day: 1, month: 5} = 1st May 1989 or new Date()
  148. * @accessor
  149. */
  150.  
  151. /**
  152. * @cfg {Boolean} destroyPickerOnHide
  153. * Whether or not to destroy the picker widget on hide. This save memory if it's not used frequently,
  154. * but increase delay time on the next show due to re-instantiation. Defaults to false
  155. * @accessor
  156. */
  157. destroyPickerOnHide: false,
  158.  
  159. /**
  160. * @cfg {String} dateTimeFormat The format to be used when displaying the date in this field.
  161. * Accepts any valid datetime format. You can view formats over in the {@link Ext.Date} documentation.
  162. * Defaults to `Ext.util.Format.defaultDateFormat`.
  163. */
  164. dateTimeFormat: 'm/d/Y h:i:A',
  165. /**
  166. * @cfg {Object}
  167. * @hide
  168. */
  169. component: {
  170. useMask: true
  171. }
  172. },
  173.  
  174. initialize: function() {
  175. this.callParent();
  176.  
  177. this.getComponent().on({
  178. scope: this,
  179.  
  180. masktap: 'onMaskTap'
  181. });
  182.  
  183. this.getComponent().input.dom.disabled = true;
  184. },
  185.  
  186. syncEmptyCls: Ext.emptyFn,
  187.  
  188. applyValue: function(value) {
  189. if (!Ext.isDate(value) && !Ext.isObject(value)) {
  190. value = null;
  191. }
  192.  
  193. if (Ext.isObject(value)) {
  194. value = new Date(value.year, value.month - 1, value.day,value.hour,value.minute);
  195. }
  196.  
  197. return value;
  198. },
  199.  
  200. updateValue: function(newValue) {
  201. var picker = this._picker;
  202. if (picker && picker.isPicker) {
  203. picker.setValue(newValue);
  204. }
  205.  
  206. // Ext.Date.format expects a Date
  207. if (newValue !== null) {
  208. this.getComponent().setValue(Ext.Date.format(newValue, this.getDateTimeFormat() || Ext.util.Format.defaultDateFormat));
  209. } else {
  210. this.getComponent().setValue('');
  211. }
  212.  
  213. if (this._picker && this._picker instanceof Ext.ux.picker.DateTime) {
  214. this._picker.setValue(newValue);
  215. }
  216. },
  217.  
  218. /**
  219. * Updates the date format in the field.
  220. * @private
  221. */
  222. updateDateFormat: function(newDateFormat, oldDateFormat) {
  223. var value = this.getValue();
  224. if (newDateFormat != oldDateFormat && Ext.isDate(value) && this._picker && this._picker instanceof Ext.ux.picker.DateTime) {
  225. this.getComponent().setValue(Ext.Date.format(value, newDateFormat || Ext.util.Format.defaultDateFormat));
  226. }
  227. },
  228.  
  229. /**
  230. * Returns the {@link Date} value of this field.
  231. * If you wanted a formated date
  232. * @return {Date} The date selected
  233. */
  234. getValue: function() {
  235. if (this._picker && this._picker instanceof Ext.ux.picker.DateTime) {
  236. return this._picker.getValue();
  237. }
  238.  
  239. return this._value;
  240. },
  241.  
  242. /**
  243. * Returns the value of the field formatted using the specified format. If it is not specified, it will default to
  244. * {@link #dateFormat} and then {@link Ext.util.Format#defaultDateFormat}.
  245. * @param {String} format The format to be returned
  246. * @return {String} The formatted date
  247. */
  248. getFormattedValue: function(format) {
  249. var value = this.getValue();
  250. console.log(this.getDateTimeFormat(),"format");
  251. return (Ext.isDate(value)) ? Ext.Date.format(value, format || this.getDateTimeFormat() || Ext.util.Format.defaultDateFormat) : value;
  252. },
  253.  
  254. applyPicker: function(picker, pickerInstance) {
  255. if (pickerInstance && pickerInstance.isPicker) {
  256. picker = pickerInstance.setConfig(picker);
  257. }
  258.  
  259. return picker;
  260. },
  261.  
  262. getPicker: function() {
  263. var picker = this._picker,
  264. value = this.getValue();
  265.  
  266. if (picker && !picker.isPicker) {
  267. picker = Ext.factory(picker, Ext.ux.picker.DateTime);
  268. picker.on({
  269. scope: this,
  270. cancel: 'onPickerCancel',
  271. change: 'onPickerChange',
  272. hide : 'onPickerHide'
  273. });
  274.  
  275. if (value !== null) {
  276. picker.setValue(value);
  277. }
  278.  
  279. Ext.Viewport.add(picker);
  280. this._picker = picker;
  281. }
  282.  
  283. return picker;
  284. },
  285.  
  286. /**
  287. * @private
  288. * Listener to the tap event of the mask element. Shows the internal DatePicker component when the button has been tapped.
  289. */
  290. onMaskTap: function(e) {
  291. if (this.getDisabled()) {
  292. return false;
  293. }
  294.  
  295. if (this.getReadOnly()) {
  296. return false;
  297. }
  298.  
  299. // Make sure to fire the focus event
  300. this.fireEvent('focus', this, e);
  301.  
  302. this.getPicker().show();
  303.  
  304. return false;
  305. },
  306.  
  307. /**
  308. * @private
  309. * Revert internal date so field won't appear changed
  310. */
  311. onPickerCancel: function(picker, options) {
  312. if (this.getDestroyPickerOnHide() && picker) {
  313. this._picker = this._picker.config;
  314. picker.destroy();
  315. }
  316. return true;
  317. },
  318.  
  319. /**
  320. * Called when the picker changes its value
  321. * @param {Ext.ux.picker.DateTime} picker The date picker
  322. * @param {Object} value The new value from the date picker
  323. * @private
  324. */
  325. onPickerChange: function(picker, value) {
  326. var me = this;
  327.  
  328. me.setValue(value);
  329. me.fireEvent('change', me, me.getValue());
  330. },
  331.  
  332. /**
  333. * Destroys the picker when it is hidden, if
  334. * {@link Ext.ux.field.DateTimePicker#destroyPickerOnHide destroyPickerOnHide} is set to true
  335. * @private
  336. */
  337. onPickerHide: function() {
  338. var picker = this.getPicker();
  339. if (this.getDestroyPickerOnHide() && picker) {
  340. picker.destroy();
  341. this._picker = true;
  342. }
  343. },
  344.  
  345. reset: function() {
  346. this.setValue(this.originalValue);
  347. },
  348.  
  349. // @private
  350. destroy: function() {
  351. var picker = this.getPicker();
  352.  
  353. if (picker && picker.isPicker) {
  354. picker.destroy();
  355. }
  356.  
  357. this.callParent(arguments);
  358. }
  359. //<deprecated product=touch since=2.0>
  360. }, function() {
  361. this.override({
  362. getValue: function(format) {
  363. if (format) {
  364. //<debug warn>
  365. Ext.Logger.deprecate("format argument of the getValue method is deprecated, please use getFormattedValue instead", this);
  366. //</debug>
  367. return this.getFormattedValue(format);
  368. }
  369. return this.callOverridden();
  370. }
  371. });
  372.  
  373. /**
  374. * @method getDatePicker
  375. * @inheritdoc Ext.ux.field.DateTimePicker#getPicker
  376. * @deprecated 2.0.0 Please use #getPicker instead
  377. */
  378. Ext.deprecateMethod(this, 'getDatePicker', 'getPicker');
  379. //</deprecated>
  380. });

[控件]unigui移动端下Unidatepicker时间显示解决方案的更多相关文章

  1. 关于Devexpress15.2中GridControl控件选择字段ColumnEdit下拉时间设置

    效果:点击表格GridControl控件中的列,可以显示日期和时间.时间可以手动修改.(绑定日期格式的字段) 设置步骤:1.点击时间字段列表设置ColumnEdit-New-选择DateEdit出现r ...

  2. atitit.组件化事件化的编程模型--服务端控件(1)---------服务端控件与标签的关系

    atitit.组件化事件化的编程模型--服务端控件(1)---------服务端控件与标签的关系 1. 服务器控件是可被服务器理解的标签.有三种类型的服务器控件: 1 1.1. HTML 服务器控件  ...

  3. #include <objsafe.h>//OCX控件在IE8浏览器下不能使用问题

    一.OCX控件开发常见的问题 1.OCX控件在IE8浏览器下不能使用问题 原因:IE8会拦截OCX控件的方法. 解决方法:在OCX控件开发时加入安全接口. (1)在有"Crtl"字 ...

  4. WPF 控件被禁用,悬浮提示不显示问题

    原文:WPF 控件被禁用,悬浮提示不显示问题 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/89 ...

  5. VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法。

    原文:VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net ...

  6. GridControl控件绑定RepositoryItemImageComboBox 作为下拉框使用

    如果,时间长时了,已前做过的东西,都记不得了,所以记录一下. 废话不多说. 1.拖出gridview控件,然后将字段绑定上去 2.将要做下拉框的控件加入RepositoryItemImageCombo ...

  7. Android 布局控件——滚动条视图,日期,时间

    今天学长讲了一些控件,比较强的那种控件. 刚开始讲了图片,但是图片我前面写过了就跳过. 滚动条牛牛们应该很熟悉,也常用哈. 这是垂直的滚动条视图哈 一起来用吧! <ScrollView andr ...

  8. 第一个开源控件:Google 官方下拉刷新控件 SwipeRefreshLayout 强化版,支持上拉刷新

    最近比较闲,所以趁着这时间撸了个SwipeRefreshLayout的加强版,Github地址. 原版只支持下拉刷新,强化之后支持上拉刷新和一进入页面就加载刷新,整个控件的加载动画是一致的,毫无违和感 ...

  9. 9.2.2 .net framework下的MVC 控件的封装(下)

    控件封装的部分说明 可能有人觉得应该前后端分离,我也承认这是应该的方向,我们也在考虑使用ng2等简化前端.但是,我们封装控件还是因为如下原因综合考虑的: 我们这是个框架,上面支撑了许多个应用,包含几百 ...

随机推荐

  1. python文件读取操作、序列化

    1.对文件进行读写操作时,先建立文件句柄 f = open("test.txt","r",encoding="UTF-8") 其中,r为文件 ...

  2. default(T) 和 typeof 和 GetType()

    一.default(T) 在泛型编成中如果不限制T类型参数是值类型或引用类型的话 你程序内部可能会出现错误,因为值类型不允许NULL.所以default用来获取一个类型的默认值,对于值类型得到new ...

  3. oracle使用3DES加密

    CREATE OR REPLACE PACKAGE dbc_cryptor IS SYSKEY VARCHAR2(16) := '0000000012345678'; SYSIV VARCHAR2(1 ...

  4. InputMethodManagerService处理输入法——监听APK变动

    android\frameworks\base\services\java\com\android\server\InputMethodManagerService.java public Input ...

  5. python上下文管理协议

    所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...

  6. mac安装oh my zsh

    克隆项目到本地 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh 2.创建配置文件 cp ~/.oh-my-zsh/ ...

  7. windows10安装ubuntu on windows10

    安装向导 https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

  8. MVC 开发模式

    1.M:Model  模型:实体类和业务和dao 2.V:view  视图:JSP 3.C:Controller  控制器:servlet 3.1 作用:视图和逻辑分离 4.MVC适用场景:大型项目开 ...

  9. springboot aop+@interface实现日志记录

    一.基本概念 1.自定义注解 自定义注解我们必须了解四个元注解,什么是元注解?元注解指作用于注解之上的元数据或者元信息,简单通俗的讲,元注解就是注解的注解 . Documented与Inherited ...

  10. c# devexpress 多个窗口

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...