book.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * @File : book.js
  3. * @Author : jade
  4. * @Date : 2024/1/30 17:01
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. export class BookShort {
  10. constructor() {
  11. this.book_id = "" //id
  12. this.book_name = "" //名称
  13. this.book_pic = "" //图片
  14. this.book_remarks = "" //备注
  15. }
  16. to_dict() {
  17. return JSON.stringify(this);
  18. }
  19. load_dic(json_str) {
  20. let obj = JSON.parse(json_str)
  21. for (let propName in obj) {
  22. this[propName] = obj[propName];
  23. }
  24. }
  25. }
  26. export class BookDetail extends BookShort {
  27. /**
  28. * let book = {
  29. * book_name: $('[property$=book_name]')[0].attribs.content,
  30. * book_year: $('[property$=update_time]')[0].attribs.content,
  31. * book_director: $('[property$=author]')[0].attribs.content,
  32. * book_content: $('[property$=description]')[0].attribs.content,
  33. * };
  34. * $ = await this.getHtml(this.siteUrl + id + `list.html`);
  35. * let urls = [];
  36. * const links = $('dl>dd>a[href*="/html/"]');
  37. * for (const l of links) {
  38. * const name = $(l).text().trim();
  39. * const link = l.attribs.href;
  40. * urls.push(name + '$' + link);
  41. * }
  42. * book.volumes = '全卷';
  43. * book.urls = urls.join('#');
  44. * return book
  45. * */
  46. constructor() {
  47. super();
  48. this.book_year = ""
  49. this.book_director = ""
  50. this.book_content = ""
  51. this.volumes = ""
  52. this.urls = ""
  53. }
  54. to_short() {
  55. let bookShort = new BookShort()
  56. bookShort.load_dic(this.to_dict())
  57. return bookShort.to_dict()
  58. }
  59. load_dic(json_str) {
  60. let obj = JSON.parse(json_str)
  61. for (let propName in obj) {
  62. this[propName] = obj[propName];
  63. console.log(propName);//打印👉属性名-->name age gender address
  64. }
  65. }
  66. }