rate.js 18 KB

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