index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Vue from 'vue';
  2. import component from './detail.vue'
  3. const detailElement = (taskid, detail = {}) => {
  4. let cloneData = (myObj) => {
  5. if (typeof (myObj) !== 'object') return myObj;
  6. if (myObj === null) return myObj;
  7. //
  8. if (typeof myObj.length === 'number') {
  9. let [...myNewObj] = myObj;
  10. return myNewObj;
  11. } else {
  12. let {...myNewObj} = myObj;
  13. return myNewObj;
  14. }
  15. };
  16. let isArray = (myObj) => {
  17. return Object.prototype.toString.call(myObj) == '[object Array]';
  18. }
  19. return new Promise(() => {
  20. let custom = Vue.extend(component);
  21. if (typeof taskid === 'object' && taskid !== null) {
  22. detail = cloneData(taskid);
  23. taskid = parseInt(taskid.id);
  24. if (isNaN(taskid)) {
  25. taskid = 0;
  26. }
  27. }
  28. if (typeof detail !== 'object' || detail === null) {
  29. detail = {}
  30. }
  31. if (typeof taskid === "number") {
  32. detail.taskid = taskid;
  33. }
  34. if (!isArray(detail.subtask)) {
  35. detail.subtask = [];
  36. }
  37. let data = {
  38. taskid: taskid,
  39. detail: detail,
  40. };
  41. let instance = new custom({
  42. data: data
  43. });
  44. instance.$mount();
  45. document.body.appendChild(instance.$el);
  46. })
  47. };
  48. export default detailElement