rate.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(246);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 117:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/utils/dom");
  85. /***/ },
  86. /***/ 246:
  87. /***/ function(module, exports, __webpack_require__) {
  88. 'use strict';
  89. exports.__esModule = true;
  90. var _main = __webpack_require__(247);
  91. var _main2 = _interopRequireDefault(_main);
  92. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  93. /* istanbul ignore next */
  94. _main2.default.install = function (Vue) {
  95. Vue.component(_main2.default.name, _main2.default);
  96. };
  97. exports.default = _main2.default;
  98. /***/ },
  99. /***/ 247:
  100. /***/ function(module, exports, __webpack_require__) {
  101. var Component = __webpack_require__(3)(
  102. /* script */
  103. __webpack_require__(248),
  104. /* template */
  105. __webpack_require__(249),
  106. /* scopeId */
  107. null,
  108. /* cssModules */
  109. null
  110. )
  111. module.exports = Component.exports
  112. /***/ },
  113. /***/ 248:
  114. /***/ function(module, exports, __webpack_require__) {
  115. 'use strict';
  116. exports.__esModule = true;
  117. var _dom = __webpack_require__(117);
  118. exports.default = {
  119. name: 'ElRate',
  120. data: function data() {
  121. return {
  122. classMap: {},
  123. colorMap: {},
  124. pointerAtLeftHalf: false,
  125. currentValue: this.value,
  126. hoverIndex: -1
  127. };
  128. },
  129. props: {
  130. value: {
  131. type: Number,
  132. default: 0
  133. },
  134. lowThreshold: {
  135. type: Number,
  136. default: 2
  137. },
  138. highThreshold: {
  139. type: Number,
  140. default: 4
  141. },
  142. max: {
  143. type: Number,
  144. default: 5
  145. },
  146. colors: {
  147. type: Array,
  148. default: function _default() {
  149. return ['#F7BA2A', '#F7BA2A', '#F7BA2A'];
  150. }
  151. },
  152. voidColor: {
  153. type: String,
  154. default: '#C6D1DE'
  155. },
  156. disabledVoidColor: {
  157. type: String,
  158. default: '#EFF2F7'
  159. },
  160. iconClasses: {
  161. type: Array,
  162. default: function _default() {
  163. return ['el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on'];
  164. }
  165. },
  166. voidIconClass: {
  167. type: String,
  168. default: 'el-icon-star-off'
  169. },
  170. disabledVoidIconClass: {
  171. type: String,
  172. default: 'el-icon-star-on'
  173. },
  174. disabled: {
  175. type: Boolean,
  176. default: false
  177. },
  178. allowHalf: {
  179. type: Boolean,
  180. default: false
  181. },
  182. showText: {
  183. type: Boolean,
  184. default: false
  185. },
  186. textColor: {
  187. type: String,
  188. default: '#1f2d3d'
  189. },
  190. texts: {
  191. type: Array,
  192. default: function _default() {
  193. return ['极差', '失望', '一般', '满意', '惊喜'];
  194. }
  195. },
  196. textTemplate: {
  197. type: String,
  198. default: '{value}'
  199. }
  200. },
  201. computed: {
  202. text: function text() {
  203. var result = '';
  204. if (this.disabled) {
  205. result = this.textTemplate.replace(/\{\s*value\s*\}/, this.value);
  206. } else {
  207. result = this.texts[Math.ceil(this.currentValue) - 1];
  208. }
  209. return result;
  210. },
  211. decimalStyle: function decimalStyle() {
  212. var width = '';
  213. if (this.disabled) {
  214. width = (this.valueDecimal < 50 ? 0 : 50) + '%';
  215. }
  216. if (this.allowHalf) {
  217. width = '50%';
  218. }
  219. return {
  220. color: this.activeColor,
  221. width: width
  222. };
  223. },
  224. valueDecimal: function valueDecimal() {
  225. return this.value * 100 - Math.floor(this.value) * 100;
  226. },
  227. decimalIconClass: function decimalIconClass() {
  228. return this.getValueFromMap(this.value, this.classMap);
  229. },
  230. voidClass: function voidClass() {
  231. return this.disabled ? this.classMap.disabledVoidClass : this.classMap.voidClass;
  232. },
  233. activeClass: function activeClass() {
  234. return this.getValueFromMap(this.currentValue, this.classMap);
  235. },
  236. activeColor: function activeColor() {
  237. return this.getValueFromMap(this.currentValue, this.colorMap);
  238. },
  239. classes: function classes() {
  240. var result = [];
  241. var i = 0;
  242. var threshold = this.currentValue;
  243. if (this.allowHalf && this.currentValue !== Math.floor(this.currentValue)) {
  244. threshold--;
  245. }
  246. for (; i < threshold; i++) {
  247. result.push(this.activeClass);
  248. }
  249. for (; i < this.max; i++) {
  250. result.push(this.voidClass);
  251. }
  252. return result;
  253. }
  254. },
  255. watch: {
  256. value: function value(val) {
  257. this.$emit('change', val);
  258. this.currentValue = val;
  259. }
  260. },
  261. methods: {
  262. getValueFromMap: function getValueFromMap(value, map) {
  263. var result = '';
  264. if (value <= this.lowThreshold) {
  265. result = map.lowColor || map.lowClass;
  266. } else if (value >= this.highThreshold) {
  267. result = map.highColor || map.highClass;
  268. } else {
  269. result = map.mediumColor || map.mediumClass;
  270. }
  271. return result;
  272. },
  273. showDecimalIcon: function showDecimalIcon(item) {
  274. var showWhenDisabled = this.disabled && this.valueDecimal > 0 && item - 1 < this.value && item > this.value;
  275. /* istanbul ignore next */
  276. var showWhenAllowHalf = this.allowHalf && this.pointerAtLeftHalf && (item - 0.5).toFixed(1) === this.currentValue.toFixed(1);
  277. return showWhenDisabled || showWhenAllowHalf;
  278. },
  279. getIconStyle: function getIconStyle(item) {
  280. var voidColor = this.disabled ? this.colorMap.disabledVoidColor : this.colorMap.voidColor;
  281. return {
  282. color: item <= this.currentValue ? this.activeColor : voidColor
  283. };
  284. },
  285. selectValue: function selectValue(value) {
  286. if (this.disabled) {
  287. return;
  288. }
  289. if (this.allowHalf && this.pointerAtLeftHalf) {
  290. this.$emit('input', this.currentValue);
  291. } else {
  292. this.$emit('input', value);
  293. }
  294. },
  295. setCurrentValue: function setCurrentValue(value, event) {
  296. if (this.disabled) {
  297. return;
  298. }
  299. /* istanbul ignore if */
  300. if (this.allowHalf) {
  301. var target = event.target;
  302. if ((0, _dom.hasClass)(target, 'el-rate__item')) {
  303. target = target.querySelector('.el-rate__icon');
  304. }
  305. if ((0, _dom.hasClass)(target, 'el-rate__decimal')) {
  306. target = target.parentNode;
  307. }
  308. this.pointerAtLeftHalf = event.offsetX * 2 <= target.clientWidth;
  309. this.currentValue = this.pointerAtLeftHalf ? value - 0.5 : value;
  310. } else {
  311. this.currentValue = value;
  312. }
  313. this.hoverIndex = value;
  314. },
  315. resetCurrentValue: function resetCurrentValue() {
  316. if (this.disabled) {
  317. return;
  318. }
  319. if (this.allowHalf) {
  320. this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
  321. }
  322. this.currentValue = this.value;
  323. this.hoverIndex = -1;
  324. }
  325. },
  326. created: function created() {
  327. if (!this.value) {
  328. this.$emit('input', 0);
  329. }
  330. this.classMap = {
  331. lowClass: this.iconClasses[0],
  332. mediumClass: this.iconClasses[1],
  333. highClass: this.iconClasses[2],
  334. voidClass: this.voidIconClass,
  335. disabledVoidClass: this.disabledVoidIconClass
  336. };
  337. this.colorMap = {
  338. lowColor: this.colors[0],
  339. mediumColor: this.colors[1],
  340. highColor: this.colors[2],
  341. voidColor: this.voidColor,
  342. disabledVoidColor: this.disabledVoidColor
  343. };
  344. }
  345. }; //
  346. //
  347. //
  348. //
  349. //
  350. //
  351. //
  352. //
  353. //
  354. //
  355. //
  356. //
  357. //
  358. //
  359. //
  360. //
  361. //
  362. //
  363. //
  364. //
  365. //
  366. //
  367. //
  368. //
  369. //
  370. /***/ },
  371. /***/ 249:
  372. /***/ function(module, exports) {
  373. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  374. return _c('div', {
  375. staticClass: "el-rate"
  376. }, [_vm._l((_vm.max), function(item) {
  377. return _c('span', {
  378. staticClass: "el-rate__item",
  379. style: ({
  380. cursor: _vm.disabled ? 'auto' : 'pointer'
  381. }),
  382. on: {
  383. "mousemove": function($event) {
  384. _vm.setCurrentValue(item, $event)
  385. },
  386. "mouseleave": _vm.resetCurrentValue,
  387. "click": function($event) {
  388. _vm.selectValue(item)
  389. }
  390. }
  391. }, [_c('i', {
  392. staticClass: "el-rate__icon",
  393. class: [_vm.classes[item - 1], {
  394. 'hover': _vm.hoverIndex === item
  395. }],
  396. style: (_vm.getIconStyle(item))
  397. }, [(_vm.showDecimalIcon(item)) ? _c('i', {
  398. staticClass: "el-rate__decimal",
  399. class: _vm.decimalIconClass,
  400. style: (_vm.decimalStyle)
  401. }) : _vm._e()])])
  402. }), (_vm.showText) ? _c('span', {
  403. staticClass: "el-rate__text",
  404. style: ({
  405. color: _vm.textColor
  406. })
  407. }, [_vm._v(_vm._s(_vm.text))]) : _vm._e()], 2)
  408. },staticRenderFns: []}
  409. /***/ }
  410. /******/ });