index.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. // pages/index/jingdianchaxun/jingdianchaxun.js
  2. const app = getApp()
  3. Page({
  4. data: {
  5. weightedMenuItems: [],
  6. layoutType: 'default',
  7. layoutConfig: {},
  8. featureLayout: [],
  9. latitude: 36.5,
  10. longitude: 118.0,
  11. scale: 7,
  12. showImageModal: false,
  13. currentMarker: null,
  14. showWebView: false,
  15. webViewUrl: "",
  16. currentVrTitle: "",
  17. searchText: "",
  18. // 新增控制变量
  19. showSearchMarkers: false,
  20. searchMarkers: [] , // 新增绿色搜索标记
  21. markers: [
  22. {
  23. id: 1,
  24. latitude: 36.665282,
  25. longitude: 117.119999,
  26. width: 30, // 添加宽度
  27. height: 30, // 添加高度
  28. title: '济南战役纪念馆',
  29. address: '市中区英雄山路18号',
  30. iconPath: '/images/red-marker.png',
  31. callout: {
  32. content: '济南战役纪念馆\n华东地区规模最大的革命烈士纪念地',
  33. color: '#000',
  34. fontSize: 14,
  35. borderRadius: 5,
  36. bgColor: '#fff',
  37. padding: 5,
  38. display: 'ALWAYS'
  39. },
  40. imageUrl: 'https://smp.ouc.edu.cn/_upload/article/images/f5/0d/85b29d70430a9261ef3830f24970/959ccc6d-b829-4d3f-8335-2c776c9faca7.png',
  41. description: '济南革命烈士陵园,坐落在泉城济南英雄山风景区,占地480亩,于1949年建成。陵园分为革命烈士纪念塔、济南战役纪念馆、革命烈士墓区、"胜利"铜雕、毛泽东主席凭吊革命烈士纪念亭和济南革命烈士纪念群雕等纪念建筑物。陵园以济南战役纪念馆为中心,形成了辐射全市范围的红色旅游景区。是山东省规模最大的烈士陵园,1977年被公布为山东省第一批重点文物保护单位。',
  42. detail: [
  43. { label: '开放时间', value: '9:00-16:00(周一闭馆,周二至周日开馆)' },
  44. { label: '门票', value: '免费' }
  45. ]
  46. },
  47. {
  48. id: 2,
  49. latitude: 36.090839,
  50. longitude: 120.384428,
  51. title: '青岛革命烈士纪念馆',
  52. address: '市南区芝泉路6号',
  53. width: 30, // 添加宽度
  54. height: 30, // 添加高度
  55. iconPath: '/images/red-marker.png',
  56. callout: {
  57. content: '青岛革命烈士纪念馆\n山东省重点文物保护单位',
  58. color: '#000',
  59. fontSize: 14,
  60. borderRadius: 5,
  61. bgColor: '#fff',
  62. padding: 5,
  63. display: 'ALWAYS'
  64. },
  65. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/730e0cf3d7ca7bcb0a463bb5de507c63f6246a6002ad?x-bce-process=image/format,f_auto/quality,Q_70/resize,m_lfit,limit_1,w_536',
  66. description: '青岛市革命烈士纪念馆(青岛市烈士纪念设施保护中心)位于市南区芝泉路6号,建立于1977年,1981年6月对外开放,占地面积35512平方米,总建筑面积4050平方米。主要纪念设施有烈士纪念堂、抗战馆、军魂馆、"山河魂"烈士群雕、烈士英名碑、流芳亭等。主要承担烈士纪念活动、烈士纪念设施保护及宣教褒扬等工作。被评为国家级烈士纪念设施,国家、省、市爱国主义教育基地,山东省党史教育基地,山东省国防教育基地,山东省党员教育基地,山东省退役军人思想政治教育基地等。',
  67. detail: [
  68. { label: '开放时间', value: '9:00-16:30(周一闭馆)' },
  69. { label: '门票', value: '免费' }
  70. ]
  71. },
  72. {
  73. id: 3,
  74. latitude: 36.804685,
  75. longitude: 118.055008,
  76. title: '黑铁山抗日武装起义纪念馆',
  77. address: '张店区四宝山街道',
  78. width: 30, // 添加宽度
  79. height: 30, // 添加高度
  80. iconPath: '/images/red-marker.png',
  81. callout: {
  82. content: '黑铁山起义纪念地\n山东抗日三大起义之一',
  83. color: '#000',
  84. fontSize: 14,
  85. borderRadius: 5,
  86. bgColor: '#fff',
  87. padding: 5,
  88. display: 'ALWAYS'
  89. },
  90. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/d8f9d72a6059252dd42a4051e4c8143b5bb5c9ea1310?x-bce-process=image/format,f_auto/watermark,image_d2F0ZXIvYmFpa2UyNzI,g_7,xp_5,yp_5,P_20/resize,m_lfit,limit_1,h_1080',
  91. description: '黑铁山抗日武装起义纪念馆于1995年纪念抗日战争胜利50周年之际奠基,于1996年8月1日落成开馆。由张店区委区政府发出倡议,号召张店区党政机关、人民大众捐资160万元而兴建。主体为二层楼,建筑面积1300平方米。为淄博市市级重点烈士纪念建筑物保护单位、山东省爱国主义教育基地。',
  92. detail: [
  93. { label: '开放时间', value: '上午8:30-11:30 下午13:30-17:00(周一闭馆)' },
  94. { label: '门票', value: '具体收费情况以现场公示为主' }
  95. ]
  96. },
  97. {
  98. id: 4,
  99. latitude: 34.810488,
  100. longitude: 117.323725,
  101. title: '台儿庄大战纪念馆',
  102. width: 30, // 添加宽度
  103. height: 30, // 添加高度
  104. address: '台儿庄区沿河南路6号',
  105. iconPath: '/images/red-marker.png',
  106. callout: {
  107. content: '台儿庄大战纪念馆\n抗日战争正面战场首次重大胜利',
  108. color: '#000',
  109. fontSize: 14,
  110. borderRadius: 5,
  111. bgColor: '#fff',
  112. padding: 5,
  113. display: 'ALWAYS'
  114. },
  115. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/58ee3d6d55fbb2fbee8d1683414a20a44723dcf9?x-bce-process=image/format,f_auto/watermark,image_d2F0ZXIvYmFpa2UyNzI,g_7,xp_5,yp_5,P_20/resize,m_lfit,limit_1,h_1080',
  116. description: '台儿庄大战纪念馆,位于山东省枣庄市台儿庄区城区西南郊,是为了纪念抗日战争初期著名的台儿庄战役而修建,于1992年由台儿庄区人民政府筹资建成,1993年4月8日正式对外开放,后经扩建,占地面积达96亩,建筑面积1.2万平方米。台儿庄大战纪念馆由纪念碑、陈列馆、影视馆、全景画馆、战地记者馆、无名英雄墓、国防教育园等部分组成,并设有临时展厅、多功能报告厅和红色图书室。展出文物、图片和史料2000余件,通过历史文物、历史图片、文献资料与各类辅助陈列手段的有机结合,全景再现台儿庄大战中爱国将士报效祖国的壮举。截至2022年底,馆有藏品数量6598件/套,年度观众总数为155323人。台儿庄大战纪念馆是全国百家爱国主义教育示范基地、全国中小学爱国主义教育基地、中国侨联爱国主义教育基地、国家首批国防教育示范基地、国家AAAA级旅游景区,并曾多年获评"山东省文明单位"。2014年8月24日,台儿庄大战纪念馆被列入《第一批国家级抗战纪念设施、遗址名录》。',
  117. detail: [
  118. { label: '开放时间', value: '8:00-17:00(全年)' },
  119. { label: '门票', value: '免费' }
  120. ]
  121. },
  122. {
  123. id: 5,
  124. latitude: 37.058161,
  125. longitude: 118.406168,
  126. width: 30, // 添加宽度
  127. height: 30, // 添加高度
  128. title: '东营市历史博物馆',
  129. address: '广饶街道月河路270号',
  130. iconPath: '/images/red-marker.png',
  131. callout: {
  132. content: '东营市历史博物馆\n中共刘集支部旧址所在地',
  133. color: '#000',
  134. fontSize: 14,
  135. borderRadius: 5,
  136. bgColor: '#fff',
  137. padding: 5,
  138. display: 'ALWAYS'
  139. },
  140. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/6a600c338744ebf816436f04d8f9d72a6059a7de?x-bce-process=image/format,f_auto/resize,m_lfit,limit_1,w_504',
  141. description: '东营市历史博物馆成立于1993年5月,坐落在东营市南部的广饶县城,东连关帝庙和孙武祠,南临月河公园,西靠月河路,北依广饶宾馆,占地面积30余亩。新馆于2002年1月开工建设,2003年10月建成,总建筑面积6812平方米,全框架结构,外观庄重大方,地上三层,地下一层,陈列总面积3500平方米。',
  142. detail: [
  143. { label: '开放时间', value: '夏8: 00 —11:30,14:00—17:30;冬8: 00 —11:30,13:30—17:00(周一闭馆)' },
  144. { label: '门票', value: '免费' }
  145. ]
  146. },
  147. {
  148. id: 6,
  149. latitude: 37.540619,
  150. longitude: 121.390736,
  151. width: 30, // 添加宽度
  152. height: 30, // 添加高度
  153. title: '胶东革命纪念馆',
  154. address: '芝罘区海岸路20号',
  155. iconPath: '/images/red-marker.png',
  156. callout: {
  157. content: '胶东革命纪念馆\n胶东地区革命历史展示中心',
  158. color: '#000',
  159. fontSize: 14,
  160. borderRadius: 5,
  161. bgColor: '#fff',
  162. padding: 5,
  163. display: 'ALWAYS'
  164. },
  165. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/c8177f3e6709c93d70cf743ec971efdcd100bba1feec?x-bce-process=image/format,f_auto/quality,Q_70/resize,m_lfit,limit_1,w_536',
  166. description: '胶东革命纪念馆位于烟台,占地面积5600平方米,展陈面积2800平方米,旧址于1865年修建,是全国重点文物保护单位。2018年7月1日起,该馆面向市民免费开放,每周一、周四闭馆。基本陈列包括英雄胶东、奋发图强、走向辉煌三个部分,展示了胶东人民在中国共产党领导下近百年来从苦难到辉煌。',
  167. detail: [
  168. { label: '开放时间', value: '9:00——16:00(每周一、周四闭馆法定节假日除外)' },
  169. { label: '门票', value: '免费' }
  170. ]
  171. },
  172. {
  173. id: 7,
  174. latitude: 36.707668,
  175. longitude: 119.161748,
  176. width: 30, // 添加宽度
  177. height: 30, // 添加高度
  178. title: '潍县集中营旧址',
  179. address: '奎文区广文街道',
  180. iconPath: '/images/red-marker.png',
  181. callout: {
  182. content: '潍县集中营旧址\n二战期间亚洲最大侨民集中营',
  183. color: '#000',
  184. fontSize: 14,
  185. borderRadius: 5,
  186. bgColor: '#fff',
  187. padding: 5,
  188. display: 'ALWAYS'
  189. },
  190. imageUrl: 'https://www.iwenbo.fun/storage/heritage/20210131/60169f37505f5.jpg',
  191. description: '潍县西方侨民集中营旧址,又名乐道院集中营、山东集中营,位于山东省潍坊市奎文区乐道院。清光绪八年(1882年),美国基督教长老会派牧师狄乐播偕夫人阿撤拉氏(一说为狄珍珠)来潍县传教,在老潍县东关处买地建立"乐道院",乐道院由教堂、学堂、诊所3部分组成,用以传教、办学和开办诊所。民国三十一年(1942年)至民国三十四年(1945年),日军在潍县西方侨民集中营旧址设立"敌国人员生活所",一度成为二战期间亚洲境内最大的"集中营"。从1996年起,潍坊市政府先后投资对潍县西方侨民集中营旧址十字楼进行了修缮,建设纪念碑和乐道广场、乐道雕塑,建成展览馆和陈列馆,并对周边河道进行了治理,进行"乐道钟声"景观公园建设,对观众免费开放。作为二战期间亚洲最大的外国侨民集中营旧址——潍县西方侨民集中营旧址,承载着世界反法西斯战争共同的伤痛记忆,对于拓宽公共外交空间具有不可替代的地位和重要作用。2019年10月,潍县西方侨民集中营旧址被中华人民共和国国务院公布为第八批全国重点文物保护单位。',
  192. detail: [
  193. { label: '开放时间', value: '夏9:00-17:00;冬9:00-16:30(周一闭馆)' },
  194. { label: '门票', value: '免费' }
  195. ]
  196. },
  197. {
  198. id: 8,
  199. latitude: 35.414921,
  200. longitude: 116.587116,
  201. width: 30, // 添加宽度
  202. height: 30, // 添加高度
  203. title: '微山湖抗日英烈纪念园',
  204. address: '微山县微山岛镇',
  205. iconPath: '/images/red-marker.png',
  206. callout: {
  207. content: '微山湖抗日纪念园\n铁道游击队主要活动区域',
  208. color: '#000',
  209. fontSize: 14,
  210. borderRadius: 5,
  211. bgColor: '#fff',
  212. padding: 5,
  213. display: 'ALWAYS'
  214. },
  215. imageUrl: 'https://bkimg.cdn.bcebos.com/pic/34fae6cd7b899e510fb319ddf4fece33c895d043a7fb?x-bce-process=image/format,f_auto/watermark,image_d2F0ZXIvYmFpa2UyNzI,g_7,xp_5,yp_5,P_20/resize,m_lfit,limit_1,h_1080',
  216. description: '微山湖英烈纪念园,位于山东省微山县夏镇西港,始建于1982年,共投资1100余万元,占地33000平方米,原名为微山县烈士陵园,是为纪念微山湖区革命武装和湖区人民团结抗日,浴血奋战而修建的烈士纪念设施。微山湖英烈纪念园内安葬不同时期牺牲的革命烈士587名。著名烈士有"华东战斗英雄"郭继胜、抗日英雄褚雅青、爆破英雄种衍海等。著名战斗主要有杏园战斗、部城遭遇战、收复微山岛、大捐战斗、南庄战斗、程子庙战斗等。纪念园内主要建筑物有微山湖抗日游击大队纪念碑、微山县烈士英名碑、著名烈士墓区、鲁南战役烈士纪念碑、微山湖区党史纪念馆、文史馆等。整座纪念园布局严谨,绿草如茵,松柏苍翠。2014年,经济宁市人民政府批准,微山湖英烈纪念园被列入市级烈士纪念设施保护单位。',
  217. detail: [
  218. { label: '开放时间', value: '8:30—17:30(农历除夕至大年初三闭园)' },
  219. { label: '门票', value: '免费' }
  220. ]
  221. },
  222. {
  223. id: 9,
  224. latitude: 36.200371,
  225. longitude: 117.087614,
  226. width: 30, // 添加宽度
  227. height: 30, // 添加高度
  228. title: '陆房突围胜利纪念馆',
  229. address: '肥城市安临站镇',
  230. iconPath: '/images/red-marker.png',
  231. callout: {
  232. content: '陆房突围纪念馆\n八路军115师突围战纪念地',
  233. color: '#000',
  234. fontSize: 14,
  235. borderRadius: 5,
  236. bgColor: '#fff',
  237. padding: 5,
  238. display: 'ALWAYS'
  239. },
  240. imageUrl: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.rMYotSx3O8zaY_LHeW03NgHaE8?w=246&h=180&c=7&r=0&o=7&dpr=1.8&pid=1.7&rm=3',
  241. description: '陆房突围胜利纪念馆是为纪念1939年八路军一一五师陆房突围战役而设立的专题纪念馆。该馆始建于1971年,2015年完成扩建后建筑面积达5300平方米,现陈列包含战斗文物、历史文献及军民生活用品等260件/套藏品。截至2023年,年接待量达18万人次,累计接待单位400余个。2024年8月获评国家二级博物馆,同时被列为国家级抗战纪念设施、遗址及省级爱国主义教育基地',
  242. detail: [
  243. { label: '开放时间', value: '夏9:00 - 11:30,15:00 - 17:30;冬9:00 - 11:30,14:30 - 17:00(周一闭馆)' },
  244. { label: '门票', value: '免费' }
  245. ]
  246. },
  247. {
  248. id: 10,
  249. latitude: 37.501314,
  250. longitude: 122.113556,
  251. width: 30, // 添加宽度
  252. height: 30, // 添加高度
  253. title: '天福山起义纪念馆',
  254. address: '文登区天福山',
  255. iconPath: '/images/red-marker.png',
  256. callout: {
  257. content: '天福山起义纪念馆\n山东人民抗日救国军诞生地',
  258. color: '#000',
  259. fontSize: 14,
  260. borderRadius: 5,
  261. bgColor: '#fff',
  262. padding: 5,
  263. display: 'ALWAYS'
  264. },
  265. imageUrl: 'https://example.com/tianfu-mountain.jpg',
  266. description: '天福山起义纪念馆位于山东省威海市文登区文登营镇天福山森林公园中心,建筑面积450平方米,陈列面积420平方米。1989年,拆除原有简易展厅,在原址上重新扩建420平方米平房展厅。主要陈列有《天福山起义原址》《中共胶东特委会议旧址》《天福山武装起义会场》《天福山起义纪念塔》等。主要藏品有《三军战士用过的枪支》《军旗、军号、印鉴》《大刀、铁矛头、节鞭》等文物藏品。截至2019年末,天福天福山起义纪念馆先后获得"山东省爱国主义教育基地"、"山东省优秀国防教育基地"等荣誉称号。',
  267. detail: [
  268. { label: '开放时间', value: '8:30-11:00,13:30-17:00(周一闭馆)' },
  269. { label: '门票', value: '免费' }
  270. ]
  271. }
  272. ],
  273. storyList: [
  274. {
  275. id: 1,
  276. cover: '/images/index/台儿庄.jpg',
  277. title: '台儿庄战役'
  278. },
  279. {
  280. id: 2,
  281. cover: '/images/index/沂蒙山革命.webp',
  282. title: '沂蒙山革命'
  283. },
  284. {
  285. id: 3,
  286. cover: '/images/index/济南革命烈士.jpg',
  287. title: '济南革命烈士'
  288. },
  289. {
  290. id: 4,
  291. cover: '/images/index/铁道游击队.webp',
  292. title: '铁道游击队'
  293. },
  294. {
  295. id: 5,
  296. cover: '/images/index/莱芜战役.jpg',
  297. title: '莱芜战役'
  298. },
  299. {
  300. id: 6,
  301. cover: '/images/index/羊山战役.png',
  302. title: '阳山战役'
  303. }
  304. ],
  305. vrList: [
  306. {
  307. id: 1,
  308. title: "聊城革命烈士陵园",
  309. desc: "360°全景展示",
  310. thumb: "https://bkimg.cdn.bcebos.com/pic/43a7d933c895d143ad4bb00002a995025aafa40fa9c5?x-bce-process=image/format,f_auto/quality,Q_70/resize,m_lfit,limit_1,w_536",
  311. url: "https://www.720yun.com/vr/f27j5puurv1"
  312. },
  313. {
  314. id: 2,
  315. title: "台儿庄大战纪念馆",
  316. desc: "沉浸式VR体验",
  317. thumb: "https://bkimg.cdn.bcebos.com/pic/58ee3d6d55fbb2fbee8d1683414a20a44723dcf9?x-bce-process=image/format,f_auto/watermark,image_d2F0ZXIvYmFpa2UyNzI,g_7,xp_5,yp_5,P_20/resize,m_lfit,limit_1,h_1080",
  318. url: "https://www.720yun.com/vr/6f4jtrwaOn5"
  319. },
  320. {
  321. id: 3,
  322. title: "鲁西南战役纪念馆",
  323. desc: "刘邓大军千里跃进",
  324. thumb: "https://bkimg.cdn.bcebos.com/pic/7a899e510fb30f2442a7769cd7dac643ad4bd113a557?x-bce-process=image/format,f_auto/quality,Q_70/resize,m_lfit,limit_1,w_536",
  325. url: "https://www.720yun.com/vr/a982acOfyna"
  326. },
  327. {
  328. id: 4,
  329. title: "孟良崮战役纪念馆",
  330. desc: "解放战争",
  331. thumb: "https://bkimg.cdn.bcebos.com/pic/b3119313b07eca806538b17b007280dda144ad342557?x-bce-process=image/format,f_auto/watermark,image_d2F0ZXIvYmFpa2UyNzI,g_7,xp_5,yp_5,P_20/resize,m_lfit,limit_1,h_1080",
  332. url: "https://www.720yun.com/vr/3d9jOstmrk2"
  333. },
  334. {
  335. id: 5,
  336. title: "昌邑抗日殉国烈士祠",
  337. desc: "全国重点文物保护单位",
  338. thumb: "http://www.changyibwg.cn/upload/default/20200509/756dff458ee61cb41428e42b9b2019e5.jpg",
  339. url: "https://www.720yun.com/vr/5fajOstmrk4"
  340. }
  341. ],
  342. touchStartX: 0,
  343. touchStartY: 0,
  344. positionX: 0,
  345. positionY: 0,
  346. showMenu: false,
  347. walking: false,
  348. windowWidth: 0,
  349. windowHeight: 0
  350. },
  351. onLoad: function(options) {
  352. this.getMenuWeights();
  353. this.getLayoutRecommendation();
  354. this.mapCtx = wx.createMapContext('map');
  355. wx.getSystemInfo({
  356. success: (res) => {
  357. this.setData({
  358. windowWidth: res.windowWidth,
  359. windowHeight: res.windowHeight,
  360. positionX: res.windowWidth - 80,
  361. positionY: res.windowHeight - 180
  362. });
  363. }
  364. });
  365. },
  366. getMenuWeights: function() {
  367. wx.request({
  368. url: 'http://127.0.0.1:8000/api/recommend-layout/',
  369. header: { 'Authorization': `Token ${app.globalData.userInfo.token}` },
  370. success: (res) => {
  371. if (res.data && res.data.features) {
  372. console.log(res.data.features);
  373. this.processMenuData(res.data.features);
  374. }
  375. },
  376. fail: () => {
  377. // 失败时使用默认布局
  378. this.setDefaultMenu();
  379. }
  380. });
  381. },
  382. // 处理菜单数据
  383. processMenuData: function(features) {
  384. // 菜单配置映射 - 更新键名与feature_name保持一致
  385. const menuConfig = {
  386. 'ai-plan': {
  387. title: '红途定制',
  388. icon: '/images/index/生成攻略.png',
  389. url: '/pages/ai-plan/ai-plan'
  390. },
  391. 'search-all': { // 改为search-all以匹配feature_name
  392. title: '红游速搜',
  393. icon: '/images/搜索分类.png',
  394. url: '/pages/gongjiao/gongjiao'
  395. },
  396. 'quiz-main': { // 添加quiz-main的配置
  397. title: '红史问答堂',
  398. icon: '/images/index/游学路线.png',
  399. url: '/pages/quiz/quiz'
  400. }
  401. };
  402. // 过滤出有配置的功能并按priority排序(priority值越大权重越高)
  403. const validFeatures = features
  404. .filter(item => menuConfig[item.feature_name]) // 使用feature_name而非name
  405. .sort((a, b) => b.priority - a.priority); // 使用priority排序
  406. console.log('有效功能:', validFeatures);
  407. // 构建菜单项数据
  408. const menuItems = validFeatures.map((item, index) => {
  409. const config = menuConfig[item.feature_name]; // 使用feature_name
  410. return {
  411. title: config.title,
  412. icon: config.icon,
  413. url: item.page_path, // 直接使用数据中的page_path
  414. weight: item.priority, // 使用priority作为权重
  415. sizeClass: this.getSizeClass(index),
  416. isTop: index === 0
  417. };
  418. });
  419. console.log('生成的菜单项:', menuItems);
  420. this.data.weightedMenuItems=menuItems
  421. this.setData({
  422. weightedMenuItems: menuItems
  423. })
  424. console.log('生成的菜单项:', this.data.weightedMenuItems);
  425. },
  426. // 根据排序确定尺寸类别
  427. getSizeClass: function(index) {
  428. return index === 0 ? 'large' :
  429. index < 3 ? 'medium' : 'small';
  430. },
  431. // 默认菜单数据
  432. getDefaultMenuItems: function() {
  433. return [
  434. {
  435. title: '红途定制',
  436. icon: '/images/index/生成攻略.png',
  437. url: '/pages/ai-plan/ai-plan',
  438. sizeClass: 'medium',
  439. isTop: false
  440. },
  441. {
  442. title: '游学路线',
  443. icon: '/images/index/游学路线.png',
  444. url: '/pages/gongjiao/gongjiao',
  445. sizeClass: 'medium',
  446. isTop: false
  447. },
  448. {
  449. title: '红游速搜',
  450. icon: '/images/搜索分类.png',
  451. url: '/pages/search/search',
  452. sizeClass: 'medium',
  453. isTop: false
  454. }
  455. ];
  456. },
  457. getLayoutRecommendation() {
  458. wx.request({
  459. url: 'http://127.0.0.1:8000/api/recommend-layout/',
  460. method: 'GET',
  461. header: {
  462. 'Authorization': `Token ${app.globalData.userInfo.token}`
  463. },
  464. success: (res) => {
  465. console.log('布局推荐:', res.data);
  466. this.setData({
  467. layoutType: res.data.layout_type,
  468. featureWeights: res.data.feature_weights
  469. });
  470. },
  471. fail: (err) => {
  472. console.error('获取布局失败:', err);
  473. }
  474. });
  475. },
  476. generateFeatureLayout(weights) {
  477. // 根据权重生成特征布局
  478. const features = [
  479. {feature: 'ai-plan', name: '红途定制', image: '/images/index/生成攻略.png'},
  480. {feature: 'gongjiao', name: '游学路线', image: '/images/index/游学路线.png'},
  481. {feature: 'search', name: '红游速搜', image: '/images/搜索分类.png'},
  482. {feature: 'quiz', name: '红史问答', image: '/images/quiz-icon.png'}
  483. ];
  484. // 根据权重排序
  485. return features.sort((a, b) => weights[b.feature] - weights[a.feature])
  486. .map((item, index) => ({
  487. ...item,
  488. size: this.getSizeClass(index)
  489. }));
  490. },
  491. getSizeClass(index) {
  492. // 根据位置决定大小
  493. return index === 0 ? 'large' : (index < 3 ? 'medium' : 'small');
  494. },
  495. applyLayoutStyle() {
  496. // 动态应用布局样式
  497. const config = this.data.layoutConfig;
  498. const query = wx.createSelectorQuery();
  499. query.select('.map-container').boundingClientRect();
  500. query.select('.menu').boundingClientRect();
  501. query.select('.vr-container').boundingClientRect();
  502. query.exec(res => {
  503. res[0].node.setStyle({height: `${config.map * 100}vh`});
  504. res[1].node.setStyle({display: config.features > 0.3 ? 'block' : 'none'});
  505. res[2].node.setStyle({height: `${config.vr * 100}vh`});
  506. });
  507. },
  508. onSearchInput: function(e) {
  509. this.setData({
  510. searchText: e.detail.value
  511. });
  512. },
  513. searchLocation: function(keyword) {
  514. const qqMapKey = 'LOABZ-FH4LW-PGHRL-Y73W4-7WMNF-BHFQ5'; // 您的真实KEY
  515. wx.request({
  516. url: `https://apis.map.qq.com/ws/place/v1/search`,
  517. data: {
  518. keyword: keyword,
  519. boundary: 'region(山东,0)', // 限定山东范围
  520. key: qqMapKey
  521. },
  522. success: (res) => {
  523. wx.hideLoading();
  524. if (res.data.status === 0 && res.data.data) {
  525. this.processSearchResults(res.data.data);
  526. } else {
  527. wx.showToast({
  528. title: res.data.message || '搜索失败',
  529. icon: 'none'
  530. });
  531. }
  532. },
  533. fail: (err) => {
  534. wx.hideLoading();
  535. console.error('API请求失败:', err);
  536. }
  537. });
  538. },
  539. addMarker: function(location) {
  540. if (!this.mapCtx) {
  541. this.mapCtx = wx.createMapContext('map');
  542. }
  543. const newMarker = {
  544. id: Date.now(),
  545. latitude: location.lat,
  546. longitude: location.lng,
  547. title: location.name,
  548. iconPath: '/images/地点.png',
  549. width: 30,
  550. height: 30,
  551. callout: {
  552. content: location.name,
  553. color: '#fff',
  554. bgColor: '#d32f2f',
  555. padding: 8,
  556. borderRadius: 4
  557. },
  558. imageUrl: location.imageUrl || '/images/default.jpg',
  559. address: location.address,
  560. description: location.description,
  561. detail: location.detail || []
  562. };
  563. this.setData({
  564. latitude: location.lat,
  565. longitude: location.lng,
  566. scale: 12,
  567. markers: [newMarker]
  568. });
  569. this.mapCtx.moveToLocation();
  570. setTimeout(() => {
  571. this.mapCtx.translateMarker({
  572. markerId: newMarker.id,
  573. autoRotate: true,
  574. duration: 1000
  575. });
  576. }, 500);
  577. },
  578. // 点击按钮触发位置选择
  579. chooseLocation: function() {
  580. const that = this;
  581. wx.chooseLocation({
  582. success: (res) => {
  583. console.log('选择的位置:', res);
  584. // 生成绿色搜索标记(与原有红色标记共存)
  585. const newMarker = {
  586. id: Date.now(), // 动态ID避免冲突
  587. latitude: res.latitude,
  588. longitude: res.longitude,
  589. title: res.name || '已选位置',
  590. address: res.address,
  591. iconPath: '/images/search-marker.png', // 绿色标记图标
  592. width: 30,
  593. height: 30,
  594. callout: {
  595. content: res.name,
  596. color: '#fff',
  597. bgColor: '#07c160',
  598. padding: 8,
  599. display: 'ALWAYS'
  600. }
  601. };
  602. that.setData({
  603. searchMarkers: [newMarker], // 替换旧搜索标记
  604. latitude: res.latitude, // 移动视角到选中位置
  605. longitude: res.longitude,
  606. scale: 16
  607. });
  608. },
  609. fail: (err) => {
  610. console.error('位置选择失败:', err);
  611. wx.showToast({ title: '位置选择取消', icon: 'none' });
  612. }
  613. });
  614. },
  615. onSearchConfirm: function() {
  616. wx.request({
  617. url: 'https://apis.map.qq.com/ws/place/v1/search',
  618. success: (res) => {
  619. this.setData({
  620. // 生成绿色搜索标记(ID从10000开始避免冲突)
  621. searchMarkers: res.data.data.map((item, index) => ({
  622. id: 10000 + index,
  623. latitude: item.location.lat,
  624. longitude: item.location.lng,
  625. title: item.title,
  626. iconPath: '/images/search-marker.png', // 绿色图标
  627. width: 30,
  628. height: 30,
  629. callout: {
  630. content: item.title,
  631. color: '#fff',
  632. bgColor: '#07c160', // 绿色背景
  633. display: 'BYCLICK' // 点击才显示,避免遮挡
  634. }
  635. })),
  636. // 保持原有视野不变(避免红色标记移出屏幕)
  637. latitude: this.data.latitude,
  638. longitude: this.data.longitude
  639. });
  640. }
  641. });
  642. },
  643. // 在搜索成功的回调中:
  644. processSearchResults(results) {
  645. this.setData({
  646. searchMarkers: results.map((item, index) => ({
  647. id: 10000 + index, // 确保ID不冲突
  648. latitude: item.location.lat,
  649. longitude: item.location.lng,
  650. title: item.title,
  651. iconPath: '/images/search-marker.png',
  652. width: 30,
  653. height: 30
  654. })),
  655. showSearchMarkers: true,
  656. // 自动定位到第一个结果
  657. latitude: results[0].location.lat,
  658. longitude: results[0].location.lng,
  659. scale: 15
  660. });
  661. },// 标记点击事件处理(兼容原有红标和新绿标)
  662. onMarkerTap: function(e) {
  663. const markerId = e.detail.markerId;
  664. const redMarker = this.data.markers.find(m => m.id === markerId);
  665. if (redMarker) {
  666. this.setData({
  667. currentMarker: redMarker,
  668. showImageModal: true // 显示详情弹窗
  669. });
  670. return;
  671. }
  672. },
  673. hideImageModal: function() {
  674. this.setData({
  675. showImageModal: false
  676. });
  677. },
  678. stopPropagation: function() {
  679. return;
  680. },
  681. openLocation: function() {
  682. if (!this.data.currentMarker) return;
  683. wx.openLocation({
  684. latitude: this.data.currentMarker.latitude,
  685. longitude: this.data.currentMarker.longitude,
  686. name: this.data.currentMarker.title,
  687. address: this.data.currentMarker.address
  688. });
  689. },
  690. showWebView: function(e) {
  691. const { url, title } = e.currentTarget.dataset;
  692. wx.navigateTo({
  693. url: `/pages/vr-detail/vr-detail?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
  694. });
  695. },
  696. hideWebView: function() {
  697. this.setData({
  698. showWebView: false,
  699. webViewUrl: "",
  700. currentVrTitle: ""
  701. });
  702. },
  703. touchStart: function(e) {
  704. this.setData({
  705. touchStartX: e.touches[0].clientX,
  706. touchStartY: e.touches[0].clientY
  707. });
  708. },
  709. touchMove: function(e) {
  710. const { touchStartX, touchStartY } = this.data;
  711. const moveX = e.touches[0].clientX - touchStartX;
  712. const moveY = e.touches[0].clientY - touchStartY;
  713. this.setData({
  714. positionX: this.data.positionX + moveX,
  715. positionY: this.data.positionY + moveY,
  716. touchStartX: e.touches[0].clientX,
  717. touchStartY: e.touches[0].clientY
  718. });
  719. },
  720. touchEnd: function() {
  721. const { positionX, positionY, windowWidth, windowHeight } = this.data;
  722. const btnSize = 80;
  723. let finalX = positionX;
  724. let finalY = positionY;
  725. if (positionX < 0) finalX = 0;
  726. if (positionX > windowWidth - btnSize) finalX = windowWidth - btnSize;
  727. if (positionY < 0) finalY = 0;
  728. if (positionY > windowHeight - btnSize) finalY = windowHeight - btnSize;
  729. this.setData({
  730. positionX: finalX,
  731. positionY: finalY
  732. });
  733. },
  734. showFloatMenu: function() {
  735. this.setData({
  736. showMenu: true
  737. });
  738. },
  739. hideFloatMenu: function() {
  740. this.setData({
  741. showMenu: false
  742. });
  743. },
  744. doFunction1: function() {
  745. this.setData({ showMenu: false });
  746. wx.showToast({
  747. title: '功能1已触发',
  748. icon: 'none'
  749. });
  750. },
  751. doFunction2: function() {
  752. this.setData({ showMenu: false });
  753. wx.navigateTo({
  754. url: '/pages/function2/function2'
  755. });
  756. },
  757. doFunction3: function() {
  758. this.setData({ showMenu: false });
  759. wx.showModal({
  760. title: '提示',
  761. content: '确定执行功能3吗?',
  762. success(res) {
  763. if (res.confirm) {
  764. wx.showToast({
  765. title: '功能3已执行',
  766. icon: 'success'
  767. });
  768. }
  769. }
  770. });
  771. },
  772. navigateTopage: function(e) {
  773. const pagePath = e.currentTarget.dataset.url;
  774. if (pagePath) {
  775. wx.navigateTo({
  776. url: pagePath,
  777. });
  778. } else {
  779. wx.showToast({
  780. title: '功能开发中',
  781. icon: 'none'
  782. });
  783. }
  784. },
  785. viewGallery: function(e) {
  786. const id = e.currentTarget.dataset.id;
  787. wx.navigateTo({
  788. url: `/pages/gallery/detail?id=${id}`
  789. });
  790. },
  791. onReady: function() {
  792. // 页面初次渲染完成
  793. },
  794. onShow: function() {
  795. // 页面显示
  796. this.getRecommendLayout();
  797. },
  798. getRecommendLayout: function() {
  799. const token = wx.getStorageSync('token');
  800. if (!token) return;
  801. wx.request({
  802. url: 'https://your-api-domain.com/api/recommend-layout/',
  803. header: {
  804. 'Authorization': `Token ${token}`
  805. },
  806. success: (res) => {
  807. if (res.statusCode === 200) {
  808. console.log('布局推荐:', res.data);
  809. this.applyLayoutConfig(res.data);
  810. }
  811. }
  812. });
  813. },
  814. applyLayoutConfig: function(data) {
  815. const layoutMap = {
  816. 'map_focused': { map: 0.7, vr: 0.2 },
  817. 'vr_focused': { map: 0.4, vr: 0.4 },
  818. 'feature_focused': { map: 0.5, vr: 0.3 },
  819. 'default': { map: 0.6, vr: 0.3 }
  820. };
  821. // 设置布局类型
  822. const layoutType = data.layout_type || 'default';
  823. this.setData({
  824. layoutConfig: layoutMap[layoutType],
  825. featureLayout: this.generateFeatureLayout(data.recommended_order)
  826. });
  827. },
  828. // 生成功能布局
  829. generateFeatureLayout: function(features) {
  830. // 根据推荐顺序生成不同大小的布局项
  831. return features.map((feature, index) => {
  832. return {
  833. feature: feature,
  834. size: index < 2 ? 'large' : (index < 4 ? 'medium' : 'small')
  835. };
  836. }).slice(0, 6); // 只显示前6个功能
  837. },
  838. recordFeatureUsage(featureName) {
  839. const app = getApp();
  840. console.log('发送的Token:', app.globalData.userInfo.token);
  841. console.log('发送的featureName:', featureName);
  842. wx.request({
  843. url: 'http://127.0.0.1:8000/api/record-usage/',
  844. method: 'POST',
  845. header: {
  846. 'Authorization': `Token ${app.globalData.userInfo.token}`,
  847. 'Content-Type': 'application/json' // 确保这个请求头存在
  848. },
  849. data: JSON.stringify({ // 关键修改:必须使用JSON.stringify
  850. feature_name: featureName // 参数名必须与后端一致
  851. }),
  852. success: (res) => {
  853. console.log('行为记录响应:', res.data);
  854. },
  855. fail: (err) => {
  856. console.error('请求失败:', err);
  857. }
  858. });
  859. },
  860. onHide: function() {
  861. // 页面隐藏
  862. },
  863. onUnload: function() {
  864. // 页面卸载
  865. },
  866. onPullDownRefresh: function() {
  867. wx.stopPullDownRefresh();
  868. },
  869. onReachBottom: function() {
  870. // 上拉加载更多
  871. },
  872. onShareAppMessage: function() {
  873. return {
  874. title: '山东红色景点地图',
  875. path: '/pages/index/jingdianchaxun/jingdianchaxun',
  876. imageUrl: '/images/share.jpg'
  877. };
  878. },
  879. onPageScroll: function() {
  880. // 页面滚动
  881. },
  882. onTabItemTap: function(item) {
  883. // tab点击
  884. },
  885. onResize: function() {
  886. // 页面尺寸变化
  887. }
  888. });