rate.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 319);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 3:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/utils/dom");
  166. /***/ }),
  167. /***/ 319:
  168. /***/ (function(module, exports, __webpack_require__) {
  169. "use strict";
  170. exports.__esModule = true;
  171. var _main = __webpack_require__(320);
  172. var _main2 = _interopRequireDefault(_main);
  173. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  174. /* istanbul ignore next */
  175. _main2.default.install = function (Vue) {
  176. Vue.component(_main2.default.name, _main2.default);
  177. };
  178. exports.default = _main2.default;
  179. /***/ }),
  180. /***/ 320:
  181. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  182. "use strict";
  183. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  184. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__ = __webpack_require__(321);
  185. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__);
  186. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_02f4e282_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(322);
  187. var normalizeComponent = __webpack_require__(0)
  188. /* script */
  189. /* template */
  190. /* template functional */
  191. var __vue_template_functional__ = false
  192. /* styles */
  193. var __vue_styles__ = null
  194. /* scopeId */
  195. var __vue_scopeId__ = null
  196. /* moduleIdentifier (server only) */
  197. var __vue_module_identifier__ = null
  198. var Component = normalizeComponent(
  199. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default.a,
  200. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_02f4e282_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
  201. __vue_template_functional__,
  202. __vue_styles__,
  203. __vue_scopeId__,
  204. __vue_module_identifier__
  205. )
  206. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  207. /***/ }),
  208. /***/ 321:
  209. /***/ (function(module, exports, __webpack_require__) {
  210. "use strict";
  211. exports.__esModule = true;
  212. var _dom = __webpack_require__(3);
  213. var _migrating = __webpack_require__(8);
  214. var _migrating2 = _interopRequireDefault(_migrating);
  215. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  216. //
  217. //
  218. //
  219. //
  220. //
  221. //
  222. //
  223. //
  224. //
  225. //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. exports.default = {
  251. name: 'ElRate',
  252. mixins: [_migrating2.default],
  253. inject: {
  254. elForm: {
  255. default: ''
  256. }
  257. },
  258. data: function data() {
  259. return {
  260. pointerAtLeftHalf: true,
  261. currentValue: this.value,
  262. hoverIndex: -1
  263. };
  264. },
  265. props: {
  266. value: {
  267. type: Number,
  268. default: 0
  269. },
  270. lowThreshold: {
  271. type: Number,
  272. default: 2
  273. },
  274. highThreshold: {
  275. type: Number,
  276. default: 4
  277. },
  278. max: {
  279. type: Number,
  280. default: 5
  281. },
  282. colors: {
  283. type: Array,
  284. default: function _default() {
  285. return ['#F7BA2A', '#F7BA2A', '#F7BA2A'];
  286. }
  287. },
  288. voidColor: {
  289. type: String,
  290. default: '#C6D1DE'
  291. },
  292. disabledVoidColor: {
  293. type: String,
  294. default: '#EFF2F7'
  295. },
  296. iconClasses: {
  297. type: Array,
  298. default: function _default() {
  299. return ['el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on'];
  300. }
  301. },
  302. voidIconClass: {
  303. type: String,
  304. default: 'el-icon-star-off'
  305. },
  306. disabledVoidIconClass: {
  307. type: String,
  308. default: 'el-icon-star-on'
  309. },
  310. disabled: {
  311. type: Boolean,
  312. default: false
  313. },
  314. allowHalf: {
  315. type: Boolean,
  316. default: false
  317. },
  318. showText: {
  319. type: Boolean,
  320. default: false
  321. },
  322. showScore: {
  323. type: Boolean,
  324. default: false
  325. },
  326. textColor: {
  327. type: String,
  328. default: '#1f2d3d'
  329. },
  330. texts: {
  331. type: Array,
  332. default: function _default() {
  333. return ['极差', '失望', '一般', '满意', '惊喜'];
  334. }
  335. },
  336. scoreTemplate: {
  337. type: String,
  338. default: '{value}'
  339. }
  340. },
  341. computed: {
  342. text: function text() {
  343. var result = '';
  344. if (this.showScore) {
  345. result = this.scoreTemplate.replace(/\{\s*value\s*\}/, this.rateDisabled ? this.value : this.currentValue);
  346. } else if (this.showText) {
  347. result = this.texts[Math.ceil(this.currentValue) - 1];
  348. }
  349. return result;
  350. },
  351. decimalStyle: function decimalStyle() {
  352. var width = '';
  353. if (this.rateDisabled) {
  354. width = (this.valueDecimal < 50 ? 0 : 50) + '%';
  355. }
  356. if (this.allowHalf) {
  357. width = '50%';
  358. }
  359. return {
  360. color: this.activeColor,
  361. width: width
  362. };
  363. },
  364. valueDecimal: function valueDecimal() {
  365. return this.value * 100 - Math.floor(this.value) * 100;
  366. },
  367. decimalIconClass: function decimalIconClass() {
  368. return this.getValueFromMap(this.value, this.classMap);
  369. },
  370. voidClass: function voidClass() {
  371. return this.rateDisabled ? this.classMap.disabledVoidClass : this.classMap.voidClass;
  372. },
  373. activeClass: function activeClass() {
  374. return this.getValueFromMap(this.currentValue, this.classMap);
  375. },
  376. colorMap: function colorMap() {
  377. return {
  378. lowColor: this.colors[0],
  379. mediumColor: this.colors[1],
  380. highColor: this.colors[2],
  381. voidColor: this.voidColor,
  382. disabledVoidColor: this.disabledVoidColor
  383. };
  384. },
  385. activeColor: function activeColor() {
  386. return this.getValueFromMap(this.currentValue, this.colorMap);
  387. },
  388. classes: function classes() {
  389. var result = [];
  390. var i = 0;
  391. var threshold = this.currentValue;
  392. if (this.allowHalf && this.currentValue !== Math.floor(this.currentValue)) {
  393. threshold--;
  394. }
  395. for (; i < threshold; i++) {
  396. result.push(this.activeClass);
  397. }
  398. for (; i < this.max; i++) {
  399. result.push(this.voidClass);
  400. }
  401. return result;
  402. },
  403. classMap: function classMap() {
  404. return {
  405. lowClass: this.iconClasses[0],
  406. mediumClass: this.iconClasses[1],
  407. highClass: this.iconClasses[2],
  408. voidClass: this.voidIconClass,
  409. disabledVoidClass: this.disabledVoidIconClass
  410. };
  411. },
  412. rateDisabled: function rateDisabled() {
  413. return this.disabled || (this.elForm || {}).disabled;
  414. }
  415. },
  416. watch: {
  417. value: function value(val) {
  418. this.currentValue = val;
  419. this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
  420. }
  421. },
  422. methods: {
  423. getMigratingConfig: function getMigratingConfig() {
  424. return {
  425. props: {
  426. 'text-template': 'text-template is renamed to score-template.'
  427. }
  428. };
  429. },
  430. getValueFromMap: function getValueFromMap(value, map) {
  431. var result = '';
  432. if (value <= this.lowThreshold) {
  433. result = map.lowColor || map.lowClass;
  434. } else if (value >= this.highThreshold) {
  435. result = map.highColor || map.highClass;
  436. } else {
  437. result = map.mediumColor || map.mediumClass;
  438. }
  439. return result;
  440. },
  441. showDecimalIcon: function showDecimalIcon(item) {
  442. var showWhenDisabled = this.rateDisabled && this.valueDecimal > 0 && item - 1 < this.value && item > this.value;
  443. /* istanbul ignore next */
  444. var showWhenAllowHalf = this.allowHalf && this.pointerAtLeftHalf && item - 0.5 <= this.currentValue && item > this.currentValue;
  445. return showWhenDisabled || showWhenAllowHalf;
  446. },
  447. getIconStyle: function getIconStyle(item) {
  448. var voidColor = this.rateDisabled ? this.colorMap.disabledVoidColor : this.colorMap.voidColor;
  449. return {
  450. color: item <= this.currentValue ? this.activeColor : voidColor
  451. };
  452. },
  453. selectValue: function selectValue(value) {
  454. if (this.rateDisabled) {
  455. return;
  456. }
  457. if (this.allowHalf && this.pointerAtLeftHalf) {
  458. this.$emit('input', this.currentValue);
  459. this.$emit('change', this.currentValue);
  460. } else {
  461. this.$emit('input', value);
  462. this.$emit('change', value);
  463. }
  464. },
  465. handleKey: function handleKey(e) {
  466. if (this.rateDisabled) {
  467. return;
  468. }
  469. var currentValue = this.currentValue;
  470. var keyCode = e.keyCode;
  471. if (keyCode === 38 || keyCode === 39) {
  472. // left / down
  473. if (this.allowHalf) {
  474. currentValue += 0.5;
  475. } else {
  476. currentValue += 1;
  477. }
  478. e.stopPropagation();
  479. e.preventDefault();
  480. } else if (keyCode === 37 || keyCode === 40) {
  481. if (this.allowHalf) {
  482. currentValue -= 0.5;
  483. } else {
  484. currentValue -= 1;
  485. }
  486. e.stopPropagation();
  487. e.preventDefault();
  488. }
  489. currentValue = currentValue < 0 ? 0 : currentValue;
  490. currentValue = currentValue > this.max ? this.max : currentValue;
  491. this.$emit('input', currentValue);
  492. this.$emit('change', currentValue);
  493. },
  494. setCurrentValue: function setCurrentValue(value, event) {
  495. if (this.rateDisabled) {
  496. return;
  497. }
  498. /* istanbul ignore if */
  499. if (this.allowHalf) {
  500. var target = event.target;
  501. if ((0, _dom.hasClass)(target, 'el-rate__item')) {
  502. target = target.querySelector('.el-rate__icon');
  503. }
  504. if ((0, _dom.hasClass)(target, 'el-rate__decimal')) {
  505. target = target.parentNode;
  506. }
  507. this.pointerAtLeftHalf = event.offsetX * 2 <= target.clientWidth;
  508. this.currentValue = this.pointerAtLeftHalf ? value - 0.5 : value;
  509. } else {
  510. this.currentValue = value;
  511. }
  512. this.hoverIndex = value;
  513. },
  514. resetCurrentValue: function resetCurrentValue() {
  515. if (this.rateDisabled) {
  516. return;
  517. }
  518. if (this.allowHalf) {
  519. this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
  520. }
  521. this.currentValue = this.value;
  522. this.hoverIndex = -1;
  523. }
  524. },
  525. created: function created() {
  526. if (!this.value) {
  527. this.$emit('input', 0);
  528. }
  529. }
  530. };
  531. /***/ }),
  532. /***/ 322:
  533. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  534. "use strict";
  535. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-rate",attrs:{"role":"slider","aria-valuenow":_vm.currentValue,"aria-valuetext":_vm.text,"aria-valuemin":"0","aria-valuemax":_vm.max,"tabindex":"0"},on:{"keydown":_vm.handleKey}},[_vm._l((_vm.max),function(item,key){return _c('span',{key:key,staticClass:"el-rate__item",style:({ cursor: _vm.rateDisabled ? 'auto' : 'pointer' }),on:{"mousemove":function($event){_vm.setCurrentValue(item, $event)},"mouseleave":_vm.resetCurrentValue,"click":function($event){_vm.selectValue(item)}}},[_c('i',{staticClass:"el-rate__icon",class:[_vm.classes[item - 1], { 'hover': _vm.hoverIndex === item }],style:(_vm.getIconStyle(item))},[(_vm.showDecimalIcon(item))?_c('i',{staticClass:"el-rate__decimal",class:_vm.decimalIconClass,style:(_vm.decimalStyle)}):_vm._e()])])}),(_vm.showText || _vm.showScore)?_c('span',{staticClass:"el-rate__text",style:({ color: _vm.textColor })},[_vm._v(_vm._s(_vm.text))]):_vm._e()],2)}
  536. var staticRenderFns = []
  537. var esExports = { render: render, staticRenderFns: staticRenderFns }
  538. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  539. /***/ }),
  540. /***/ 8:
  541. /***/ (function(module, exports) {
  542. module.exports = require("element-ui/lib/mixins/migrating");
  543. /***/ })
  544. /******/ });