common.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. function isArray(value) {
  2. if (typeof Array.isArray === 'function') {
  3. return Array.isArray(value);
  4. } else {
  5. return Object.prototype.toString.call(value) === '[object Array]';
  6. }
  7. }
  8. function isObject(value) {
  9. return Object.prototype.toString.call(value) === '[object Object]';
  10. }
  11. function isNumber(value) {
  12. return !isNaN(Number(value));
  13. }
  14. function isFunction(value) {
  15. return typeof value == 'function';
  16. }
  17. function isString(value) {
  18. return typeof value == 'string';
  19. }
  20. function isEmpty(value) {
  21. if (isArray(value)) {
  22. return value.length === 0;
  23. }
  24. if (isObject(value)) {
  25. return Object.keys(value).length === 0;
  26. }
  27. return value === '' || typeof value === 'undefined' || value === null;
  28. }
  29. function isBoolean(value) {
  30. return typeof value === 'boolean';
  31. }
  32. function composeFilter(search, op) {
  33. let filter = {};
  34. Object.keys(search).forEach((k) => {
  35. if (isObject(search[k])) {
  36. if (!isEmpty(search[k].value) && search[k].value !== 'all') {
  37. let stype = '=';
  38. if (op && op[search[k].field]) {
  39. if (isObject(op[search[k].field])) {
  40. stype = op[search[k].field].type || '=';
  41. } else {
  42. stype = op[search[k].field];
  43. }
  44. }
  45. filter[search[k].field] = [search[k].value, stype];
  46. }
  47. } else {
  48. if (!isEmpty(search[k]) && search[k] !== 'all') {
  49. let stype = '=';
  50. if (op && op[k]) {
  51. if (isObject(op[k])) {
  52. stype = op[k].type || '=';
  53. } else {
  54. stype = op[k];
  55. }
  56. }
  57. filter[k] = [
  58. isArray(search[k]) ? search[k].join(`${op[k].spacer ? op[k].spacer : ' - '}`) : search[k],
  59. stype,
  60. ];
  61. }
  62. }
  63. });
  64. return { search: JSON.stringify(filter) };
  65. }
  66. function onClipboard(text) {
  67. const clipboard = new ClipboardJS(`<div></div>`, {
  68. text: () => text,
  69. });
  70. clipboard.on('success', () => {
  71. ElementPlus.ElMessage({
  72. message: '复制成功',
  73. type: 'success',
  74. });
  75. clipboard.destroy();
  76. });
  77. clipboard.on('error', () => {
  78. ElementPlus.ElMessage({
  79. message: '复制失败',
  80. type: 'warning',
  81. });
  82. clipboard.destroy();
  83. });
  84. clipboard.onClick(event);
  85. }
  86. function createApp(id, testIndex) {
  87. const { createApp } = Vue
  88. const app = createApp(testIndex)
  89. app.use(ElementPlus, { locale: ElementPlusLocaleZhCn })
  90. for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  91. app.component(key, component)
  92. }
  93. app.component('draggable', window.vuedraggable)
  94. app.component('sa-image', SaImage)
  95. app.component('sa-uploader', SaUploader)
  96. app.component('sa-user-profile', SaUserProfile)
  97. app.component('sa-filter', SaFilter)
  98. app.component('sa-filter-condition', SaFilterCondition)
  99. app.component('sa-pagination', SaPagination)
  100. app.mount(`#${id}`)
  101. };