FrontService.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User : zgcLives
  5. * CreateTime : 2023/5/3 10:54
  6. */
  7. namespace addons\exam\library;
  8. class FrontService
  9. {
  10. /** 小程序页面列表 */
  11. const PAGES
  12. = [
  13. [
  14. 'path' => '/pages/index/index',
  15. 'name' => '首页',
  16. 'params' => [],
  17. 'module' => '',
  18. ],
  19. [
  20. 'path' => '/pages/search/index',
  21. 'name' => '题目搜索',
  22. 'params' => [
  23. [
  24. 'field' => 'keyword',
  25. 'name' => '搜索关键词',
  26. 'type' => 'string',
  27. 'require' => false,
  28. 'value' => '',
  29. ],
  30. ],
  31. 'module' => '',
  32. ],
  33. [
  34. 'path' => '/pages/paper/index',
  35. 'name' => '试卷列表',
  36. 'params' => [],
  37. 'module' => '',
  38. ],
  39. [
  40. 'path' => '/pages/paper/paper',
  41. 'name' => '考试试卷',
  42. 'params' => [
  43. [
  44. 'field' => 'id',
  45. 'name' => '试卷ID',
  46. 'type' => 'selectpage',
  47. 'require' => true,
  48. 'value' => '',
  49. 'selectpage' => [
  50. 'source' => 'exam/paper/index',
  51. 'field' => 'title',
  52. 'params' => [],
  53. ],
  54. ],
  55. [
  56. 'field' => 'room_id',
  57. 'name' => '考场ID',
  58. 'type' => 'selectpage',
  59. 'require' => false,
  60. 'value' => '',
  61. 'selectpage' => [
  62. 'source' => 'exam/room/index',
  63. 'field' => 'name',
  64. 'params' => [],
  65. ],
  66. ],
  67. ],
  68. 'module' => '',
  69. ],
  70. [
  71. 'path' => '/pages/paper/grade',
  72. 'name' => '考试记录',
  73. 'params' => [],
  74. 'module' => '',
  75. ],
  76. [
  77. 'path' => '/pages/paper/rank',
  78. 'name' => '考试排行榜',
  79. 'params' => [
  80. [
  81. 'field' => 'paper_id',
  82. 'name' => '试卷ID',
  83. 'type' => 'selectpage',
  84. 'require' => true,
  85. 'value' => '',
  86. 'selectpage' => [
  87. 'source' => 'exam/paper/index',
  88. 'field' => 'title',
  89. 'params' => [],
  90. ],
  91. ],
  92. ],
  93. 'module' => '',
  94. ],
  95. [
  96. 'path' => '/pages/room/index',
  97. 'name' => '考场列表',
  98. 'params' => [],
  99. 'module' => '',
  100. ],
  101. [
  102. 'path' => '/pages/room/detail',
  103. 'name' => '考场详情',
  104. 'params' => [
  105. [
  106. 'field' => 'id',
  107. 'name' => '考场ID',
  108. 'type' => 'selectpage',
  109. 'require' => true,
  110. 'value' => '',
  111. 'selectpage' => [
  112. 'source' => 'exam/room/index',
  113. 'field' => 'name',
  114. 'params' => [],
  115. ],
  116. ],
  117. ],
  118. 'module' => '',
  119. ],
  120. [
  121. 'path' => '/pages/room/grade',
  122. 'name' => '考场成绩',
  123. 'params' => [],
  124. 'module' => '',
  125. ],
  126. [
  127. 'path' => '/pages/room/rank',
  128. 'name' => '考场排行榜',
  129. 'params' => [
  130. [
  131. 'field' => 'paper_id',
  132. 'name' => '试卷ID',
  133. 'type' => 'selectpage',
  134. 'require' => true,
  135. 'value' => '',
  136. 'selectpage' => [
  137. 'source' => 'exam/paper/index',
  138. 'field' => 'title',
  139. 'params' => [],
  140. ],
  141. ],
  142. [
  143. 'field' => 'room_id',
  144. 'name' => '考场ID',
  145. 'type' => 'selectpage',
  146. 'require' => true,
  147. 'value' => '',
  148. 'selectpage' => [
  149. 'source' => 'exam/room/index',
  150. 'field' => 'name',
  151. 'params' => [],
  152. ],
  153. ],
  154. ],
  155. 'module' => '',
  156. ],
  157. [
  158. 'path' => '/pages/room/signup-index',
  159. 'name' => '考场报名记录',
  160. 'params' => [],
  161. 'module' => '',
  162. ],
  163. [
  164. 'path' => '/pages/user/user',
  165. 'name' => '用户中心',
  166. 'params' => [],
  167. 'module' => '',
  168. ],
  169. [
  170. 'path' => '/pages/user/set',
  171. 'name' => '个人设置',
  172. 'params' => [],
  173. 'module' => '',
  174. ],
  175. [
  176. 'path' => '/pages/user/my-cate',
  177. 'name' => '常用题库设置',
  178. 'params' => [],
  179. 'module' => '',
  180. ],
  181. [
  182. 'path' => '/pages/user/login-reg',
  183. 'name' => '登录注册',
  184. 'params' => [],
  185. 'module' => '',
  186. ],
  187. [
  188. 'path' => '/pages/collect/index',
  189. 'name' => '我的收藏',
  190. 'params' => [],
  191. 'module' => '',
  192. ],
  193. [
  194. 'path' => '/pages/wrong/index',
  195. 'name' => '错题记录',
  196. 'params' => [],
  197. 'module' => '',
  198. ],
  199. [
  200. 'path' => '/pages/webview/webview',
  201. 'name' => '跳转网页',
  202. 'params' => [
  203. [
  204. 'field' => 'url',
  205. 'name' => '网页地址',
  206. 'type' => 'string',
  207. 'require' => true,
  208. 'value' => '',
  209. ],
  210. ],
  211. 'module' => '',
  212. ],
  213. ];
  214. /**
  215. * 获取小程序跳转路径及参数
  216. * @return string
  217. */
  218. public static function buildUrl($path, $params = [])
  219. {
  220. return $path . '?' . http_build_query($params);
  221. }
  222. /**
  223. * 替换内容里的图片CDN链接
  224. * @param $title
  225. * @return string
  226. */
  227. public static function replaceImgUrl($title)
  228. {
  229. $pattern = '/<img.*?src="(.*?)".*?>/i';
  230. $title = preg_replace_callback($pattern, function ($matches) {
  231. $full = $matches[0];
  232. if (!empty($matches[1])) {
  233. return str_replace($matches[1], cdnurl($matches[1], true), $full);
  234. }
  235. $url = $matches[1];
  236. $host = parse_url($url, PHP_URL_HOST);
  237. $cdn_host = parse_url(cdnurl('', true), PHP_URL_HOST);
  238. if ($host) {
  239. if ($host != $cdn_host) {
  240. $url = str_replace($host, $cdn_host, $url);
  241. }
  242. } else {
  243. $url = cdnurl($url, true);
  244. }
  245. // ddd($matches);
  246. return '<img src="' . $url . '">';
  247. }, $title);
  248. return $title;
  249. }
  250. }