template.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>模板</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. /* 搜索框样式 */
  15. .search-container {
  16. border: 1px solid #333;
  17. padding: 20px;
  18. border-radius: 8px;
  19. margin-bottom: 30px;
  20. }
  21. .search-box {
  22. position: relative;
  23. max-width: 100%;
  24. }
  25. .search-box input {
  26. width: 100%;
  27. padding: 12px 40px 12px 20px;
  28. border: 1px solid #ddd;
  29. border-radius: 4px;
  30. font-size: 14px;
  31. }
  32. .search-box button {
  33. position: absolute;
  34. right: 10px;
  35. top: 50%;
  36. transform: translateY(-50%);
  37. background: none;
  38. border: none;
  39. cursor: pointer;
  40. font-size: 16px;
  41. color: #666;
  42. }
  43. /* 模板区域样式 */
  44. .template-section {
  45. max-width: 1200px;
  46. margin: 0 auto;
  47. padding: 30px 20px;
  48. }
  49. .template-header {
  50. display: flex;
  51. justify-content: flex-start;
  52. align-items: flex-start;
  53. margin-bottom: 25px;
  54. flex-direction: column;
  55. }
  56. .filter-options {
  57. display: flex;
  58. margin-top: 15px;
  59. flex-direction: column;
  60. width: 100%;
  61. }
  62. .template-title {
  63. font-size: 18px;
  64. font-weight: bold;
  65. }
  66. .filter-group {
  67. display: flex;
  68. gap: 10px;
  69. flex-direction: row;
  70. align-items: center;
  71. padding: 10px;
  72. background-color: #f8f9fa;
  73. border-radius: 8px;
  74. width: fit-content;
  75. margin-bottom: 10px;
  76. }
  77. .filter-group label {
  78. font-size: 14px;
  79. color: #333;
  80. font-weight: bold;
  81. }
  82. .filter-group span {
  83. font-size: 14px;
  84. color: #333;
  85. cursor: pointer;
  86. padding: 5px 10px;
  87. border-radius: 4px;
  88. transition: background-color 0.2s, color 0.2s;
  89. }
  90. .filter-group span:hover {
  91. background-color: #e9ecef;
  92. }
  93. .template-grid {
  94. display: grid;
  95. grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  96. gap: 15px;
  97. }
  98. .template-card {
  99. background-color: #fff;
  100. border-radius: 8px;
  101. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  102. overflow: hidden;
  103. transition: transform 0.2s;
  104. }
  105. .template-card:hover {
  106. transform: translateY(-3px);
  107. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  108. }
  109. .template-thumbnail {
  110. width: 100%;
  111. height: 120px;
  112. background-color: #f0f0f0;
  113. display: flex;
  114. align-items: center;
  115. justify-content: center;
  116. font-size: 12px;
  117. color: #666;
  118. overflow: hidden;
  119. }
  120. /* 图片和视频样式 */
  121. .template-thumbnail img,
  122. .template-thumbnail video {
  123. width: 100%;
  124. height: 100%;
  125. object-fit: cover;
  126. cursor: pointer;
  127. }
  128. /* 响应式图片 */
  129. img {
  130. max-width: 100%;
  131. height: auto;
  132. }
  133. .template-info {
  134. padding: 12px;
  135. }
  136. .template-name {
  137. font-size: 14px;
  138. font-weight: bold;
  139. margin-bottom: 6px;
  140. }
  141. .template-tags {
  142. display: flex;
  143. flex-wrap: wrap;
  144. gap: 5px;
  145. margin-bottom: 10px;
  146. }
  147. .template-tag {
  148. font-size: 12px;
  149. background-color: #e9ecef;
  150. color: #666;
  151. padding: 2px 8px;
  152. border-radius: 4px;
  153. }
  154. .template-meta {
  155. display: flex;
  156. justify-content: space-between;
  157. font-size: 12px;
  158. color: #999;
  159. }
  160. /* 图片放大样式 */
  161. .template-thumbnail {
  162. position: relative;
  163. overflow: hidden;
  164. }
  165. .template-thumbnail img,
  166. .template-thumbnail video {
  167. width: 100%;
  168. height: auto;
  169. cursor: pointer;
  170. }
  171. /* 放大查看容器 */
  172. #largeViewContainer {
  173. display: none;
  174. position: fixed;
  175. top: 0;
  176. left: 0;
  177. width: 100vw;
  178. height: 100vh;
  179. background-color: rgba(0, 0, 0, 0.9);
  180. z-index: 9999;
  181. justify-content: center;
  182. align-items: center;
  183. overflow: hidden;
  184. }
  185. #largeViewContainer img,
  186. #largeViewContainer video {
  187. max-width: 90vw;
  188. max-height: 90vh;
  189. object-fit: contain;
  190. }
  191. /* 背景遮罩 */
  192. .overlay {
  193. display: none;
  194. position: fixed;
  195. top: 0;
  196. left: 0;
  197. width: 100%;
  198. height: 100%;
  199. background-color: rgba(0, 0, 0, 0.7);
  200. z-index: 9998;
  201. }
  202. </style>
  203. </head>
  204. <body>
  205. <section class="template-section">
  206. <!-- 搜索框 -->
  207. <div class="search-container">
  208. <div class="search-box">
  209. <input type="text" id="keywordInput" placeholder="搜索" value="{$keyword|default=''}">
  210. <input type="hidden" id="typeFilter" value="{$type|default=''}">
  211. <input type="hidden" id="styleFilter" value="{$style|default=''}">
  212. <button id="searchBtn" type="button">
  213. <span class="icons search-icon"></span>
  214. 搜索</button>
  215. </div>
  216. </div>
  217. <div class="template-header">
  218. <h2 class="template-title">全部模板</h2>
  219. <div class="filter-options">
  220. <div class="filter-group">
  221. <label>风格:</label>
  222. <span id="styleAll" {if condition="empty($style)"}style="background-color: #e9ecef; color: #007bff;"{else}style="color: #333;"{/if} onclick="filterByStyle('')">全部</span>
  223. {volist name="styleList" id="styleItem"}
  224. <span id="style{$styleItem}" {if condition="$style eq $styleItem"}style="background-color: #e9ecef; color: #007bff;"{else}style="color: #333;"{/if} onclick="filterByStyle('{$styleItem}')">{$styleItem}</span>
  225. {/volist}
  226. </div>
  227. <div class="filter-group">
  228. <label>模版类型:</label>
  229. <span id="typeAll" {if condition="empty($type)"}style="background-color: #e9ecef; color: #007bff;"{else}style="color: #333;"{/if} onclick="filterByType('')">全部</span>
  230. <span id="typeImage" {if condition="$type eq '文生图'"}style="background-color: #e9ecef; color: #007bff;"{else}style="color: #333;"{/if} onclick="filterByType('文生图')">图片</span>
  231. <span id="typeVideo" {if condition="$type eq '文生视频'"}style="background-color: #e9ecef; color: #007bff;"{else}style="color: #333;"{/if} onclick="filterByType('文生视频')">视频</span>
  232. </div>
  233. </div>
  234. </div>
  235. <div class="template-grid" id="templateGrid">
  236. <!-- 使用volist标签循环显示模板 -->
  237. {volist name="products" id="template"}
  238. <div class="template-card">
  239. <div class="template-thumbnail">
  240. {if condition="$template.type eq '文生图'"}
  241. <a href="/index/user/diagrams_list/id/{$template.id}.html">
  242. <img src="{$template.template_image_url}" alt="{$template.template_name}" onerror="this.src=''; this.alt='图片加载失败';">
  243. </a>
  244. {elseif condition="$template.type eq '文生视频'"}
  245. <a href="/index/user/diagrams_list/id/{$template.id}.html">
  246. <video src="{$template.template_image_url}" alt="{$template.template_name}" controls muted></video>
  247. </a>
  248. {/if}
  249. </div>
  250. <div class="template-info">
  251. <div class="template-name">{$template.template_name}</div>
  252. <div class="template-meta">
  253. <span style="color: black">{$template.nickname}</span>
  254. <span>免费</span>
  255. </div>
  256. </div>
  257. </div>
  258. {/volist}
  259. </div>
  260. </section>
  261. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  262. <script>
  263. // 初始化变量
  264. let currentKeyword = '{$keyword|default=\'\'}';
  265. let currentType = '{$type|default=\'\'}';
  266. let currentStyle = '{$style|default=\'\'}';
  267. // 搜索函数
  268. function searchTemplates() {
  269. // 获取当前的关键词、类型和风格
  270. const keyword = $('#keywordInput').val().trim();
  271. const type = $('#typeFilter').val();
  272. const style = $('#styleFilter').val();
  273. // 如果参数没有变化,不发送请求
  274. if (keyword === currentKeyword && type === currentType && style === currentStyle) {
  275. return;
  276. }
  277. // 更新当前参数
  278. currentKeyword = keyword;
  279. currentType = type;
  280. currentStyle = style;
  281. // 发送AJAX请求
  282. $.ajax({
  283. url: '{:url("index/user/template")}',
  284. type: 'GET',
  285. data: {
  286. keyword: keyword,
  287. type: type,
  288. style: style
  289. },
  290. dataType: 'json',
  291. success: function(response) {
  292. if (response.code === 0 && response.data) {
  293. // 更新模板列表
  294. updateTemplateGrid(response.data);
  295. } else {
  296. console.error('获取模板数据失败:', response.msg);
  297. }
  298. },
  299. error: function(xhr, status, error) {
  300. console.error('AJAX请求失败:', error);
  301. }
  302. });
  303. }
  304. // 更新模板网格
  305. function updateTemplateGrid(templates) {
  306. const templateGrid = $('#templateGrid');
  307. templateGrid.empty(); // 清空现有内容
  308. // 如果没有模板,显示提示
  309. if (templates.length === 0) {
  310. templateGrid.append('<div style="grid-column: 1 / -1; text-align: center; padding: 50px; color: #666;">暂无匹配的模板</div>');
  311. return;
  312. }
  313. // 循环生成模板卡片
  314. $.each(templates, function(index, template) {
  315. let mediaElement;
  316. // 根据类型创建媒体元素
  317. if (template.type === '文生图') {
  318. mediaElement = `<img src="${template.template_image_url}" alt="${template.template_name}" onerror="this.src=''; this.alt='图片加载失败';">`;
  319. } else if (template.type === '文生视频') {
  320. mediaElement = `<video src="${template.template_image_url}" alt="${template.template_name}" controls muted></video>`;
  321. }
  322. // 创建模板卡片
  323. const templateCard = `
  324. <div class="template-card">
  325. <div class="template-thumbnail">
  326. <a href="/index/user/diagrams_list/id/${template.id}.html">
  327. ${mediaElement}
  328. </a>
  329. </div>
  330. <div class="template-info">
  331. <div class="template-name">${template.template_name}</div>
  332. <div class="template-meta">
  333. <span style="color: black">${template.nickname || '未知用户'}</span>
  334. <span>免费</span>
  335. </div>
  336. </div>
  337. </div>
  338. `;
  339. templateGrid.append(templateCard);
  340. });
  341. }
  342. // 类型筛选函数
  343. function filterByType(type) {
  344. // 更新类型筛选器的值
  345. $('#typeFilter').val(type);
  346. // 更新类型筛选按钮的样式
  347. $('#typeAll, #typeImage, #typeVideo').css({'background-color': '', 'color': '#333'});
  348. if (type === '') {
  349. $('#typeAll').css({'background-color': '#e9ecef', 'color': '#007bff'});
  350. } else if (type === '文生图') {
  351. $('#typeImage').css({'background-color': '#e9ecef', 'color': '#007bff'});
  352. } else if (type === '文生视频') {
  353. $('#typeVideo').css({'background-color': '#e9ecef', 'color': '#007bff'});
  354. }
  355. // 执行搜索
  356. searchTemplates();
  357. }
  358. // 风格筛选函数
  359. function filterByStyle(style) {
  360. // 更新风格筛选器的值
  361. $('#styleFilter').val(style);
  362. // 更新风格筛选按钮的样式
  363. // 先重置所有风格按钮的样式
  364. $('.filter-group span[id^="style"]').css({'background-color': '', 'color': '#333'});
  365. // 然后设置选中的按钮样式
  366. if (style === '') {
  367. $('#styleAll').css({'background-color': '#e9ecef', 'color': '#007bff'});
  368. } else {
  369. $('#style' + style).css({'background-color': '#e9ecef', 'color': '#007bff'});
  370. }
  371. // 执行搜索
  372. searchTemplates();
  373. }
  374. // 搜索按钮点击事件
  375. $('#searchBtn').click(function() {
  376. searchTemplates();
  377. });
  378. // 搜索框回车事件
  379. $('#keywordInput').keypress(function(e) {
  380. if (e.key === 'Enter') {
  381. searchTemplates();
  382. }
  383. });
  384. // 搜索框输入事件(可选:实现实时搜索)
  385. let searchTimer;
  386. $('#keywordInput').on('input', function() {
  387. clearTimeout(searchTimer);
  388. // 延迟300ms执行搜索,避免频繁请求
  389. searchTimer = setTimeout(searchTemplates, 300);
  390. });
  391. </script>
  392. </body>
  393. </html>