vue_jqxbarcode.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div v-bind:id="id">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import '../jqwidgets/jqxcore.js';
  8. export default {
  9. props: {
  10. backgroundColor: String,
  11. displayLabel: Boolean,
  12. labelColor: String,
  13. labelFont: String,
  14. labelFontSize: Number,
  15. labelMarginBottom: Number,
  16. labelMarginTop: Number,
  17. labelPosition: String,
  18. lineColor: String,
  19. lineHeight: Number,
  20. lineWidth: Number,
  21. renderAs: String,
  22. type: String,
  23. value: String,
  24. autoCreate: {
  25. default: true,
  26. type: Boolean
  27. }
  28. },
  29. created: function () {
  30. this.id = 'jqxBarcode' + JQXLite.generateID();
  31. this.componentSelector = '#' + this.id;
  32. },
  33. mounted: function () {
  34. if (this.autoCreate) this.__createComponent__();
  35. },
  36. methods: {
  37. createComponent: function (options) {
  38. if (!this.autoCreate) this.__createComponent__(options)
  39. else console.warn('Component is already created! If you want to use createComponent, please set "autoCreate" property to "false".');
  40. },
  41. setOptions: function (options) {
  42. JQXLite(this.componentSelector).jqxBarcode(options);
  43. },
  44. getOptions: function () {
  45. const usedProps = Object.keys(this.__manageProps__());
  46. const resultToReturn = {};
  47. for (let i = 0; i < usedProps.length; i++) {
  48. resultToReturn[usedProps[i]] = JQXLite(this.componentSelector).jqxBarcode(usedProps[i]);
  49. }
  50. return resultToReturn;
  51. },
  52. export: function(format, fileName) {
  53. return JQXLite(this.componentSelector).jqxBarcode('export', format, fileName);
  54. },
  55. getDataURL: function(format) {
  56. return JQXLite(this.componentSelector).jqxBarcode('getDataURL', format);
  57. },
  58. getDataURLAsync: function(format) {
  59. return JQXLite(this.componentSelector).jqxBarcode('getDataURLAsync', format);
  60. },
  61. isValid: function() {
  62. return JQXLite(this.componentSelector).jqxBarcode('isValid');
  63. },
  64. _backgroundColor: function(arg) {
  65. if (arg !== undefined) {
  66. JQXLite(this.componentSelector).jqxBarcode('backgroundColor', arg)
  67. } else {
  68. return JQXLite(this.componentSelector).jqxBarcode('backgroundColor');
  69. }
  70. },
  71. _displayLabel: function(arg) {
  72. if (arg !== undefined) {
  73. JQXLite(this.componentSelector).jqxBarcode('displayLabel', arg)
  74. } else {
  75. return JQXLite(this.componentSelector).jqxBarcode('displayLabel');
  76. }
  77. },
  78. _labelColor: function(arg) {
  79. if (arg !== undefined) {
  80. JQXLite(this.componentSelector).jqxBarcode('labelColor', arg)
  81. } else {
  82. return JQXLite(this.componentSelector).jqxBarcode('labelColor');
  83. }
  84. },
  85. _labelFont: function(arg) {
  86. if (arg !== undefined) {
  87. JQXLite(this.componentSelector).jqxBarcode('labelFont', arg)
  88. } else {
  89. return JQXLite(this.componentSelector).jqxBarcode('labelFont');
  90. }
  91. },
  92. _labelFontSize: function(arg) {
  93. if (arg !== undefined) {
  94. JQXLite(this.componentSelector).jqxBarcode('labelFontSize', arg)
  95. } else {
  96. return JQXLite(this.componentSelector).jqxBarcode('labelFontSize');
  97. }
  98. },
  99. _labelMarginBottom: function(arg) {
  100. if (arg !== undefined) {
  101. JQXLite(this.componentSelector).jqxBarcode('labelMarginBottom', arg)
  102. } else {
  103. return JQXLite(this.componentSelector).jqxBarcode('labelMarginBottom');
  104. }
  105. },
  106. _labelMarginTop: function(arg) {
  107. if (arg !== undefined) {
  108. JQXLite(this.componentSelector).jqxBarcode('labelMarginTop', arg)
  109. } else {
  110. return JQXLite(this.componentSelector).jqxBarcode('labelMarginTop');
  111. }
  112. },
  113. _labelPosition: function(arg) {
  114. if (arg !== undefined) {
  115. JQXLite(this.componentSelector).jqxBarcode('labelPosition', arg)
  116. } else {
  117. return JQXLite(this.componentSelector).jqxBarcode('labelPosition');
  118. }
  119. },
  120. _lineColor: function(arg) {
  121. if (arg !== undefined) {
  122. JQXLite(this.componentSelector).jqxBarcode('lineColor', arg)
  123. } else {
  124. return JQXLite(this.componentSelector).jqxBarcode('lineColor');
  125. }
  126. },
  127. _lineHeight: function(arg) {
  128. if (arg !== undefined) {
  129. JQXLite(this.componentSelector).jqxBarcode('lineHeight', arg)
  130. } else {
  131. return JQXLite(this.componentSelector).jqxBarcode('lineHeight');
  132. }
  133. },
  134. _lineWidth: function(arg) {
  135. if (arg !== undefined) {
  136. JQXLite(this.componentSelector).jqxBarcode('lineWidth', arg)
  137. } else {
  138. return JQXLite(this.componentSelector).jqxBarcode('lineWidth');
  139. }
  140. },
  141. _renderAs: function(arg) {
  142. if (arg !== undefined) {
  143. JQXLite(this.componentSelector).jqxBarcode('renderAs', arg)
  144. } else {
  145. return JQXLite(this.componentSelector).jqxBarcode('renderAs');
  146. }
  147. },
  148. _type: function(arg) {
  149. if (arg !== undefined) {
  150. JQXLite(this.componentSelector).jqxBarcode('type', arg)
  151. } else {
  152. return JQXLite(this.componentSelector).jqxBarcode('type');
  153. }
  154. },
  155. _value: function(arg) {
  156. if (arg !== undefined) {
  157. JQXLite(this.componentSelector).jqxBarcode('value', arg)
  158. } else {
  159. return JQXLite(this.componentSelector).jqxBarcode('value');
  160. }
  161. },
  162. __createComponent__: function (options) {
  163. let widgetOptions;
  164. options ? widgetOptions = options : widgetOptions = this.__manageProps__();
  165. JQXLite(this.componentSelector).jqxBarcode(widgetOptions);
  166. this.__extendProps__();
  167. this.__wireEvents__();
  168. },
  169. __manageProps__: function () {
  170. const widgetProps = ['backgroundColor','displayLabel','labelColor','labelFont','labelFontSize','labelMarginBottom','labelMarginTop','labelPosition','lineColor','lineHeight','lineWidth','renderAs','type','value'];
  171. const componentProps = this.$options.propsData;
  172. let options = {};
  173. for (let prop in componentProps) {
  174. if (widgetProps.indexOf(prop) !== -1) {
  175. options[prop] = componentProps[prop];
  176. }
  177. }
  178. return options;
  179. },
  180. __extendProps__: function () {
  181. const that = this;
  182. Object.defineProperty(that, 'backgroundColor', {
  183. get: function() {
  184. return that._backgroundColor();
  185. },
  186. set: function(newValue) {
  187. that._backgroundColor(newValue);
  188. },
  189. enumerable: true,
  190. configurable: true
  191. });
  192. Object.defineProperty(that, 'displayLabel', {
  193. get: function() {
  194. return that._displayLabel();
  195. },
  196. set: function(newValue) {
  197. that._displayLabel(newValue);
  198. },
  199. enumerable: true,
  200. configurable: true
  201. });
  202. Object.defineProperty(that, 'labelColor', {
  203. get: function() {
  204. return that._labelColor();
  205. },
  206. set: function(newValue) {
  207. that._labelColor(newValue);
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. Object.defineProperty(that, 'labelFont', {
  213. get: function() {
  214. return that._labelFont();
  215. },
  216. set: function(newValue) {
  217. that._labelFont(newValue);
  218. },
  219. enumerable: true,
  220. configurable: true
  221. });
  222. Object.defineProperty(that, 'labelFontSize', {
  223. get: function() {
  224. return that._labelFontSize();
  225. },
  226. set: function(newValue) {
  227. that._labelFontSize(newValue);
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(that, 'labelMarginBottom', {
  233. get: function() {
  234. return that._labelMarginBottom();
  235. },
  236. set: function(newValue) {
  237. that._labelMarginBottom(newValue);
  238. },
  239. enumerable: true,
  240. configurable: true
  241. });
  242. Object.defineProperty(that, 'labelMarginTop', {
  243. get: function() {
  244. return that._labelMarginTop();
  245. },
  246. set: function(newValue) {
  247. that._labelMarginTop(newValue);
  248. },
  249. enumerable: true,
  250. configurable: true
  251. });
  252. Object.defineProperty(that, 'labelPosition', {
  253. get: function() {
  254. return that._labelPosition();
  255. },
  256. set: function(newValue) {
  257. that._labelPosition(newValue);
  258. },
  259. enumerable: true,
  260. configurable: true
  261. });
  262. Object.defineProperty(that, 'lineColor', {
  263. get: function() {
  264. return that._lineColor();
  265. },
  266. set: function(newValue) {
  267. that._lineColor(newValue);
  268. },
  269. enumerable: true,
  270. configurable: true
  271. });
  272. Object.defineProperty(that, 'lineHeight', {
  273. get: function() {
  274. return that._lineHeight();
  275. },
  276. set: function(newValue) {
  277. that._lineHeight(newValue);
  278. },
  279. enumerable: true,
  280. configurable: true
  281. });
  282. Object.defineProperty(that, 'lineWidth', {
  283. get: function() {
  284. return that._lineWidth();
  285. },
  286. set: function(newValue) {
  287. that._lineWidth(newValue);
  288. },
  289. enumerable: true,
  290. configurable: true
  291. });
  292. Object.defineProperty(that, 'renderAs', {
  293. get: function() {
  294. return that._renderAs();
  295. },
  296. set: function(newValue) {
  297. that._renderAs(newValue);
  298. },
  299. enumerable: true,
  300. configurable: true
  301. });
  302. Object.defineProperty(that, 'type', {
  303. get: function() {
  304. return that._type();
  305. },
  306. set: function(newValue) {
  307. that._type(newValue);
  308. },
  309. enumerable: true,
  310. configurable: true
  311. });
  312. Object.defineProperty(that, 'value', {
  313. get: function() {
  314. return that._value();
  315. },
  316. set: function(newValue) {
  317. that._value(newValue);
  318. },
  319. enumerable: true,
  320. configurable: true
  321. });
  322. },
  323. __wireEvents__: function () {
  324. const that = this;
  325. JQXLite(this.componentSelector).on('invalid', function (event) { that.$emit('invalid', event); });
  326. }
  327. }
  328. }
  329. </script>