excalidraw-versions.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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://php.tianyunperfect.cn/controller/excalidraw.php?action=get_by_id&id=${a}`,
  15. method: 'GET',
  16. success: function (response) {
  17. if (response.code === 200) {
  18. let data = response.data;
  19. // 如果没有数据
  20. if (data.length === 0) {
  21. closeWindow();
  22. }
  23. // 拼接list页面
  24. let listHtml = '';
  25. response.data.forEach(function (item) {
  26. const version = item.version;
  27. const title = item.name;
  28. if (!version) {
  29. return;
  30. }
  31. const url = `https://excalidraw.tianyunperfect.cn/?a=${a}&version=${version}`;
  32. 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>`;
  33. });
  34. // 将list页面添加到DOM中
  35. $('#list').html(listHtml);
  36. // 绑定删除按钮点击事件
  37. $('.delete-btn').click(function () {
  38. if (confirm('确认要删除吗?')) {
  39. const a = $(this).data('a');
  40. const title = $(this).data('title');
  41. const version = $(this).data('version');
  42. deleteData(a, title, version);
  43. }
  44. });
  45. }
  46. }
  47. });
  48. });
  49. function deleteData(a, title, version) {
  50. $.ajax({
  51. url: `https://php.tianyunperfect.cn/controller/excalidraw.php?action=delete&id=${a}&version=${version}`,
  52. method: 'DELETE',
  53. success: function (response) {
  54. if (response.code === 200) {
  55. window.location.reload(); // 刷新页面
  56. } else {
  57. alert(response.message);
  58. }
  59. },
  60. error: function () {
  61. alert('删除失败');
  62. }
  63. });
  64. }
  65. </script>
  66. <script src="js/util.js"></script>
  67. </head>
  68. <body>
  69. <p>版本如下:</p>
  70. <ul id="list"></ul>
  71. </body>
  72. </html>