excalidraw-versions.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>所有版本</title>
  6. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  7. <script>
  8. $(document).ready(function () {
  9. // 获取url中的参数a和title
  10. const urlParams = new URLSearchParams(window.location.search);
  11. const a = urlParams.get('a');
  12. // 异步请求数据
  13. $.ajax({
  14. url: `https://api.tianyunperfect.cn/excalidraw/get_by_id?id=${a}`,
  15. method: 'GET',
  16. success: function (response) {
  17. if (response.code === 1) {
  18. // 拼接list页面
  19. let listHtml = '';
  20. response.data.forEach(function (item) {
  21. const version = item.version;
  22. const title = item.name;
  23. if (!version) {
  24. return;
  25. }
  26. const url = `https://excalidraw.tianyunperfect.cn/?a=${a}&version=${version}`;
  27. listHtml += `<li><a href="${url}" target="_blank">${title}_${version}</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <button class="delete-btn" data-a="${a}" data-title="${title}" data-version="${version}">删除</button></li>`;
  28. });
  29. // 将list页面添加到DOM中
  30. $('#list').html(listHtml);
  31. // 绑定删除按钮点击事件
  32. $('.delete-btn').click(function () {
  33. if (confirm('确认要删除吗?')) {
  34. const a = $(this).data('a');
  35. const title = $(this).data('title');
  36. const version = $(this).data('version');
  37. deleteData(a, title, version);
  38. }
  39. });
  40. }
  41. }
  42. });
  43. });
  44. function deleteData(a, title, version) {
  45. $.ajax({
  46. url: `https://api.tianyunperfect.cn/excalidraw/delete_by_id?id=${a}&version=${version}`,
  47. method: 'DELETE',
  48. success: function (response) {
  49. if (response.code === 1) {
  50. window.location.reload(); // 刷新页面
  51. } else {
  52. alert(response.message);
  53. }
  54. },
  55. error: function () {
  56. alert('删除失败');
  57. }
  58. });
  59. }
  60. </script>
  61. </head>
  62. <body>
  63. <p>版本如下:</p>
  64. <ul id="list"></ul>
  65. </body>
  66. </html>