index.vue 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. <template>
  2. <view class="page">
  3. <!-- 步骤头部 -->
  4. <view class="header">
  5. <view class="title-row">
  6. <text class="title">新增作业</text>
  7. <text class="device-id">设备:{{ jobState.machineCode || '未知设备' }}</text>
  8. </view>
  9. <view class="step-row">
  10. <view
  11. v-for="step in steps"
  12. :key="step.id"
  13. class="step-item"
  14. >
  15. <view
  16. class="step-index"
  17. :class="{
  18. active: currentStep === step.id,
  19. done: currentStep > step.id
  20. }"
  21. >
  22. <text v-if="currentStep > step.id">✓</text>
  23. <text v-else>{{ step.id }}</text>
  24. </view>
  25. <view class="step-texts">
  26. <text class="step-title">{{ step.title }}</text>
  27. <text class="step-sub">{{ step.sub }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 主体内容 -->
  33. <view class="content">
  34. <!-- Step 1: 选择作业区域类型 & 路线类型 -->
  35. <view v-if="currentStep === 1" class="step-block">
  36. <view class="card select-card">
  37. <view class="select-title">选择作业区域类型</view>
  38. <view class="select-sub">
  39. 不同区域形状将影响后续路线生成方式,请根据实际地块选择。
  40. </view>
  41. <view class="select-tabs">
  42. <view
  43. v-for="item in areaTypes"
  44. :key="item.value"
  45. class="select-tab"
  46. :class="{ active: selectedAreaType === item.value }"
  47. @click="selectAreaType(item.value)"
  48. >
  49. <text class="select-tab-label">{{ item.label }}</text>
  50. <text class="select-tab-sub" v-if="item.desc">
  51. {{ item.desc }}
  52. </text>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="card select-card">
  57. <view class="select-title">选择路线类型</view>
  58. <view class="select-sub">
  59. 依据区域形状推荐的路线类型,后端将按所选类型生成具体作业路线。
  60. </view>
  61. <view class="select-tabs">
  62. <view
  63. v-for="route in availableRouteTypes"
  64. :key="route.value"
  65. class="select-tab small"
  66. :class="{ active: selectedRouteType === route.value }"
  67. @click="selectRouteType(route.value)"
  68. >
  69. <text class="select-tab-label">{{ route.label }}</text>
  70. <text class="select-tab-sub" v-if="route.desc">
  71. {{ route.desc }}
  72. </text>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="card tips-card">
  77. <view class="tips-title">说明</view>
  78. <view class="tips-content">
  79. <text>
  80. - 本步骤仅选择区域类型与路线类型,下一步将进入地图打点新增作业区域。
  81. </text>
  82. <text>
  83. - 当前选择会随作业一起提交至后端,用于指导路线生成策略。
  84. </text>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- Step 2: 地图打点 -->
  89. <view v-else-if="currentStep === 2" class="step-block">
  90. <!-- 地图占位 -->
  91. <view class="map-card">
  92. <view class="map-header">
  93. <text class="map-title">地图预览</text>
  94. <view class="map-header-actions">
  95. <button class="btn-location" @click="manualLocation" :loading="locating">
  96. <text class="btn-location-text">{{ locating ? '定位中...' : '📍 定位' }}</text>
  97. </button>
  98. </view>
  99. <text class="map-sub">通过遥控器移动设备,在地图上逐点记录</text>
  100. </view>
  101. <view class="map-body">
  102. <!-- 始终渲染地图容器以避免渲染时序问题;未加载脚本时容器为空白 -->
  103. <view id="mapContainer"></view>
  104. <text v-if="!amapLoaded" class="map-placeholder">
  105. 地图占位(H5 平台会加载高德地图 SDK){{
  106. '\n'
  107. }}当前模式:{{ modeLabel }}
  108. </text>
  109. </view>
  110. <view class="map-footer">
  111. <text class="map-hint">
  112. 提示:请使用遥控器移动设备到拐点位置,再点击“新增点”记录坐标。
  113. </text>
  114. </view>
  115. </view>
  116. <!-- 模式切换 -->
  117. <view class="mode-card">
  118. <view class="mode-title-row">
  119. <text class="mode-title">点位类型</text>
  120. <text class="mode-sub">在不同模式下分别记录作业区域、障碍物和返航点</text>
  121. </view>
  122. <view class="mode-tabs">
  123. <view
  124. v-for="item in modes"
  125. :key="item.value"
  126. class="mode-tab"
  127. :class="{ active: mode === item.value }"
  128. @click="switchMode(item.value)"
  129. >
  130. <text class="mode-tab-label">{{ item.label }}</text>
  131. </view>
  132. </view>
  133. </view>
  134. <!-- 控制面板 -->
  135. <view class="panel-card">
  136. <view class="panel-row">
  137. <button class="btn primary" @click="addPoint">新增点</button>
  138. <button class="btn ghost" @click="undoPoint" :disabled="!canUndo">
  139. 撤销
  140. </button>
  141. <button
  142. class="btn ghost"
  143. v-if="mode === 'obstacle'"
  144. @click="finishCurrentObstacle"
  145. :disabled="!currentObstacle.length"
  146. >
  147. 完成当前障碍物
  148. </button>
  149. </view>
  150. <view class="panel-desc">
  151. <text v-if="mode === 'area'">
  152. 作业区域至少需要 3 个点,建议为近似矩形。
  153. </text>
  154. <text v-else-if="mode === 'obstacle'">
  155. 每个障碍物可记录多个点,点击“完成当前障碍物”结束本组记录。
  156. </text>
  157. <text v-else>
  158. 仅允许 1 个返航点,重复新增会覆盖已有点。
  159. </text>
  160. </view>
  161. </view>
  162. <!-- 已记录点列表 -->
  163. <view class="list-card">
  164. <view class="list-title-row">
  165. <text class="list-title">已记录点位</text>
  166. </view>
  167. <scroll-view scroll-y class="list-scroll">
  168. <!-- 作业区域点 -->
  169. <view class="list-group">
  170. <view class="list-group-header">
  171. <text class="list-group-title">作业区域点({{ jobState.areaPoints.length }})</text>
  172. </view>
  173. <view
  174. v-if="jobState.areaPoints.length"
  175. class="point-list"
  176. >
  177. <view
  178. v-for="(p, index) in jobState.areaPoints"
  179. :key="'area-' + index"
  180. class="point-item"
  181. >
  182. <text class="point-label">P{{ index + 1 }}</text>
  183. <text class="point-coord">
  184. {{ formatPoint(p) }}
  185. </text>
  186. <text class="point-time">{{ formatPointTime(p.timestamp) }}</text>
  187. </view>
  188. </view>
  189. <view v-else class="empty-row">
  190. <text>暂未记录作业区域点</text>
  191. </view>
  192. </view>
  193. <!-- 障碍物点 -->
  194. <view class="list-group">
  195. <view class="list-group-header">
  196. <text class="list-group-title">
  197. 障碍物({{ jobState.obstacles.length + (currentObstacle.length ? 1 : 0) }} 组)
  198. </text>
  199. </view>
  200. <view
  201. v-if="jobState.obstacles.length || currentObstacle.length"
  202. class="obstacle-list"
  203. >
  204. <!-- 已完成的障碍物组 -->
  205. <view
  206. v-for="(obs, oIdx) in jobState.obstacles"
  207. :key="'obs-' + oIdx"
  208. class="obstacle-item"
  209. >
  210. <text class="obstacle-title">障碍物 {{ oIdx + 1 }}({{ obs.length }} 点)</text>
  211. <view
  212. v-for="(p, pIdx) in obs"
  213. :key="'obs-' + oIdx + '-' + pIdx"
  214. class="point-item small"
  215. >
  216. <text class="point-label">O{{ oIdx + 1 }}-{{ pIdx + 1 }}</text>
  217. <text class="point-coord">
  218. {{ formatPoint(p) }}
  219. </text>
  220. </view>
  221. </view>
  222. <!-- 正在录入中的障碍物(未点击“完成当前障碍物”之前也要实时回显) -->
  223. <view
  224. v-if="currentObstacle.length"
  225. class="obstacle-item"
  226. >
  227. <text class="obstacle-title">障碍物 {{ jobState.obstacles.length + 1 }}(录入中,{{ currentObstacle.length }} 点)</text>
  228. <view
  229. v-for="(p, pIdx) in currentObstacle"
  230. :key="'obs-current-' + pIdx"
  231. class="point-item small"
  232. >
  233. <text class="point-label">O{{ jobState.obstacles.length + 1 }}-{{ pIdx + 1 }}</text>
  234. <text class="point-coord">
  235. {{ formatPoint(p) }}
  236. </text>
  237. </view>
  238. </view>
  239. </view>
  240. <view v-else class="empty-row">
  241. <text>暂未记录障碍物点</text>
  242. </view>
  243. </view>
  244. <!-- 返航点 -->
  245. <view class="list-group">
  246. <view class="list-group-header">
  247. <text class="list-group-title">返航点</text>
  248. </view>
  249. <view v-if="jobState.returnPoint" class="point-item">
  250. <text class="point-label">R</text>
  251. <text class="point-coord">
  252. {{ formatPoint(jobState.returnPoint) }}
  253. </text>
  254. <text class="point-time">
  255. {{ formatPointTime(jobState.returnPoint.timestamp) }}
  256. </text>
  257. </view>
  258. <view v-else class="empty-row">
  259. <text>暂未设置返航点</text>
  260. </view>
  261. </view>
  262. </scroll-view>
  263. </view>
  264. </view>
  265. <!-- Step 3: 起点选择 -->
  266. <view v-else-if="currentStep === 3" class="step-block">
  267. <view class="map-card small">
  268. <view class="map-header">
  269. <text class="map-title">选择起点</text>
  270. <text class="map-sub">
  271. 从已记录的作业区域点中选择作业起点,可通过左右切换预览。
  272. </text>
  273. </view>
  274. <view class="map-body">
  275. <text class="map-placeholder">
  276. 这里显示作业区域示意图(占位){{
  277. '\n'
  278. }}当前起点:P{{ currentStartDisplay }}
  279. </text>
  280. </view>
  281. </view>
  282. <view class="panel-card">
  283. <view class="panel-row center">
  284. <button class="btn ghost" @click="prevStart" :disabled="!canChangeStart">
  285. 上一个
  286. </button>
  287. <view class="start-index">
  288. <text class="start-index-text">
  289. 起点:P{{ currentStartDisplay }}
  290. </text>
  291. </view>
  292. <button class="btn ghost" @click="nextStart" :disabled="!canChangeStart">
  293. 下一个
  294. </button>
  295. </view>
  296. <view class="panel-desc">
  297. <text>
  298. 提示:起点将决定设备的初始行进方向与作业顺序,后端会基于该起点生成具体路线。
  299. </text>
  300. </view>
  301. </view>
  302. <view class="list-card">
  303. <view class="list-title-row">
  304. <text class="list-title">作业区域点列表</text>
  305. </view>
  306. <scroll-view scroll-y class="list-scroll">
  307. <view
  308. v-for="(p, index) in jobState.areaPoints"
  309. :key="'start-' + index"
  310. class="point-item"
  311. :class="{ active: index === jobState.startPointIndex }"
  312. @click="setStartIndex(index)"
  313. >
  314. <text class="point-label">P{{ index + 1 }}</text>
  315. <text class="point-coord">{{ formatPoint(p) }}</text>
  316. </view>
  317. </scroll-view>
  318. </view>
  319. </view>
  320. <!-- Step 4: 作业信息确认 -->
  321. <view v-else-if="currentStep === 4" class="step-block">
  322. <view class="card confirm-card">
  323. <view class="confirm-title">
  324. <text>作业基本信息</text>
  325. </view>
  326. <view class="form-item required">
  327. <text class="label">作业名称</text>
  328. <input
  329. class="input"
  330. v-model="jobState.jobName"
  331. placeholder="请输入作业名称,如“Test device - 北区作业”"
  332. />
  333. </view>
  334. <view class="form-item required">
  335. <text class="label">地块ID</text>
  336. <input
  337. class="input"
  338. v-model="jobState.fieldId"
  339. placeholder="请输入地块ID"
  340. type="text"
  341. />
  342. </view>
  343. <view class="form-item required">
  344. <text class="label">路径宽度(厘米)</text>
  345. <input
  346. class="input"
  347. v-model="jobState.pathWidth"
  348. placeholder="请输入路径宽度,单位:厘米"
  349. type="number"
  350. />
  351. </view>
  352. <view class="summary-row">
  353. <text class="summary-label">作业区域类型</text>
  354. <text class="summary-value">{{ areaTypeLabel }}</text>
  355. </view>
  356. <view class="summary-row">
  357. <text class="summary-label">路线类型</text>
  358. <text class="summary-value">{{ routeTypeLabel }}</text>
  359. </view>
  360. <view class="summary-row">
  361. <text class="summary-label">作业区域点</text>
  362. <text class="summary-value">{{ jobState.areaPoints.length }} 个</text>
  363. </view>
  364. <view class="summary-row">
  365. <text class="summary-label">障碍物</text>
  366. <text class="summary-value">
  367. {{ jobState.obstacles.length }} 组
  368. </text>
  369. </view>
  370. <view class="summary-row">
  371. <text class="summary-label">返航点</text>
  372. <text class="summary-value">
  373. {{ jobState.returnPoint ? '已设置' : '未设置' }}
  374. </text>
  375. </view>
  376. <view class="summary-row">
  377. <text class="summary-label">起点索引</text>
  378. <text class="summary-value">
  379. P{{ currentStartDisplay }}
  380. </text>
  381. </view>
  382. </view>
  383. <view class="card tips-card">
  384. <view class="tips-title">说明</view>
  385. <view class="tips-content">
  386. <text>
  387. - 前端仅负责记录点位与基本配置,并在本页面完成数据完整性校验。
  388. </text>
  389. <text>
  390. - 路线生成、几何合法性校验以及调度逻辑由后端 `/api/job/create` 负责处理。
  391. </text>
  392. </view>
  393. </view>
  394. </view>
  395. </view>
  396. <!-- 步骤导航 -->
  397. <view class="footer">
  398. <button class="btn ghost" @click="prevStep" :disabled="currentStep === 1">
  399. 上一步
  400. </button>
  401. <button
  402. class="btn primary"
  403. v-if="currentStep < 4"
  404. @click="nextStep"
  405. >
  406. 下一步
  407. </button>
  408. <button
  409. class="btn primary"
  410. v-else
  411. :loading="submitting"
  412. @click="submitJob"
  413. >
  414. 完成并提交
  415. </button>
  416. </view>
  417. </view>
  418. </template>
  419. <script>
  420. import { createJob, getRealtimeData } from '@/api/services/job.js'
  421. import coordinateUtils from '@/utils/coordinateUtils.js'
  422. import { onLoad, onReady, onUnload} from '@dcloudio/uni-app'
  423. // 地图实例将保存在组件 data 的 `map` 字段中(见 data() 中的 map: null)
  424. // 我们在组件方法里设置一个绑定到全局回调的适配器,以便 AMap 的 script callback 能够调用组件内的初始化方法。
  425. // 简单模拟一个“当前设备坐标”,后续可替换为真实位置上报
  426. function mockCurrentPoint(baseIndex = 0) {
  427. const now = Date.now()
  428. const lng = 120.0 + (baseIndex % 10) * 0.0001
  429. const lat = 30.0 + (baseIndex % 10) * 0.0001
  430. return {
  431. lng,
  432. lat,
  433. timestamp: now
  434. }
  435. }
  436. export default {
  437. data() {
  438. return {
  439. currentStep: 1,
  440. steps: [
  441. { id: 1, title: '区域与路线', sub: '选择作业区域类型与路线类型' },
  442. { id: 2, title: '打点建模', sub: '作业区域 / 障碍物 / 返航点' },
  443. { id: 3, title: '选择起点', sub: '确定作业起点位置' },
  444. { id: 4, title: '信息确认', sub: '填写作业名称并提交' }
  445. ],
  446. // 区域类型与路线类型
  447. areaTypes: [
  448. {
  449. value: 'loopArea',
  450. label: '回字形区域',
  451. desc: '规则四边形地块,适合标准往返或回字形路线',
  452. routes: [{ value: 'loop', label: '回字形路线(loop)' }]
  453. },
  454. {
  455. value: 'bowArea',
  456. label: '弓子形区域',
  457. desc: '一侧为弧形或不规则,适合弓字形或自适应路线',
  458. routes: [{ value: 'bow', label: '弓子形路线(bow)' }]
  459. },
  460. {
  461. value: 'customArea',
  462. label: '自定义区域',
  463. desc: '任意多边形地块,路线由后端自适应规划',
  464. routes: [{ value: 'custom', label: '自定义路线(custom)' }]
  465. },
  466. {
  467. value: 'ridgeArea',
  468. label: '垄沟区域',
  469. desc: '存在大量垄沟或等距行的地块',
  470. routes: [{ value: 'ridge', label: '垄沟路线(ridge)' }]
  471. }
  472. ],
  473. selectedAreaType: 'loopArea',
  474. selectedRouteType: 'loop',
  475. mode: 'area', // area | obstacle | return
  476. modes: [
  477. { value: 'area', label: '作业区域点' },
  478. { value: 'obstacle', label: '障碍物点' },
  479. { value: 'return', label: '返航点' }
  480. ],
  481. currentObstacle: [],
  482. submitting: false,
  483. locating: false,
  484. // 高德地图相关
  485. map: null,
  486. amapLoaded: false,
  487. markers: [],
  488. geolocation: null, // 高德定位实例
  489. obstacleMarkers: [], // 障碍物标记数组
  490. returnMarker: null, // 返航点标记
  491. // 设备实时位置轮询(用于“遥控车 + 实时打点”)
  492. realtimeMarker: null,
  493. realtimeTimer: null,
  494. lastReportTime: null,
  495. latestRealtimeLngLat: null,
  496. polling: false,
  497. // 回字形(loopArea) 编辑相关
  498. loopMarkers: [],
  499. loopPolygon: null,
  500. loopReplaceIndex: null,
  501. // TODO: 将下面的占位 KEY 替换为真实的高德地图 Key(仅 H5 生效)
  502. // 原因: 当前使用的是示例 Key,生产环境需要使用真实的高德地图 API Key
  503. // 推荐: 从环境变量或配置文件中读取真实的高德地图 Key
  504. amapKey: '9f2cac7ea18905dd3830cf7360a43a35',
  505. jscode: '41af52e416d1fd1b15020dac066cec86',
  506. jobState: {
  507. machineCode: '',
  508. areaType: 'loopArea',
  509. routeType: 'loop',
  510. areaPoints: [],
  511. obstacles: [],
  512. returnPoint: null,
  513. startPointIndex: 0,
  514. jobName: '',
  515. fieldId: '',
  516. pathWidth: 100
  517. }
  518. ,
  519. // 回字形编辑相关图形对象(外圈逻辑已移除)
  520. areaPolygon: null
  521. }
  522. },
  523. onLoad(options) {
  524. const { machineCode, id } = options || {}
  525. if (machineCode) {
  526. this.jobState.machineCode = machineCode
  527. this.jobState.machineId = id
  528. }
  529. },
  530. // UniApp 页面就绪生命周期(H5 平台可在此初始化地图)
  531. onReady() {
  532. // 在页面就绪时再加载 AMap 脚本(确保 DOM 容器存在)
  533. if (typeof window !== 'undefined' && typeof document !== 'undefined') {
  534. // eslint-disable-next-line no-console
  535. console.log('[job-create] onReady - loading AMap script')
  536. this.loadScript()
  537. }
  538. },
  539. computed: {
  540. modeLabel() {
  541. const m = this.modes.find(m => m.value === this.mode)
  542. return m ? m.label : ''
  543. },
  544. canUndo() {
  545. if (this.mode === 'area') {
  546. return this.jobState.areaPoints.length > 0
  547. }
  548. if (this.mode === 'obstacle') {
  549. return this.currentObstacle.length > 0
  550. }
  551. if (this.mode === 'return') {
  552. return !!this.jobState.returnPoint
  553. }
  554. return false
  555. },
  556. canChangeStart() {
  557. return this.jobState.areaPoints.length > 0
  558. },
  559. currentStartDisplay() {
  560. if (!this.jobState.areaPoints.length) return '-'
  561. return this.jobState.startPointIndex + 1
  562. },
  563. // 展示当前区域类型与路线类型名称
  564. areaTypeLabel() {
  565. const a = this.areaTypes.find(a => a.value === this.jobState.areaType)
  566. return a ? a.label : ''
  567. },
  568. availableRouteTypes() {
  569. const a = this.areaTypes.find(a => a.value === this.selectedAreaType)
  570. return a ? a.routes : []
  571. },
  572. routeTypeLabel() {
  573. const list = this.areaTypes.reduce((acc, cur) => {
  574. if (cur.routes && cur.routes.length) {
  575. acc.push(...cur.routes)
  576. }
  577. return acc
  578. }, [])
  579. const r = list.find(r => r.value === this.jobState.routeType)
  580. return r ? r.label : this.jobState.routeType
  581. }
  582. },
  583. onUnload() {
  584. // 页面销毁时停止轮询
  585. this.clearRealtimePolling()
  586. // 清理所有地图标记
  587. this.clearAllMarkers()
  588. },
  589. methods: {
  590. loadScript() { // 挂载动态js
  591. // #ifdef H5
  592. // 绑定全局回调,AMap 脚本会调用 window.mapInit
  593. window.mapInit = () => {
  594. this._createMapWhenReady()
  595. }
  596. var script = document.createElement('script');
  597. script.src = `https://webapi.amap.com/maps?v=2.0&key=${this.amapKey}&callback=mapInit`;
  598. document.body.appendChild(script);
  599. this.amapLoaded = true
  600. // #endif
  601. // #ifndef H5
  602. // 非 H5 平台使用 uni-app 地图组件
  603. console.warn('当前平台不支持动态加载高德地图脚本,请使用 uni-app 地图组件')
  604. // #endif
  605. },
  606. _createMapWhenReady() {
  607. const createWhenReady = () => {
  608. // #ifdef H5
  609. const container = document.getElementById('mapContainer')
  610. if (!container) {
  611. // 容器尚未渲染,延迟重试
  612. setTimeout(createWhenReady, 200)
  613. return
  614. }
  615. // #endif
  616. // 创建基础地图实例并保存在组件 data.map 中
  617. const defaultCenter = [113.382, 22.5211]
  618. const createMapWithCenter = centerArr => {
  619. try {
  620. this.map = new AMap.Map('mapContainer', {
  621. center: centerArr || defaultCenter,
  622. zoom: 16
  623. })
  624. } catch (err) {
  625. console.error('[job-create] create map failed', err)
  626. return
  627. }
  628. // 添加卫星图层
  629. try {
  630. if (AMap.TileLayer && typeof AMap.TileLayer.Satellite === 'function') {
  631. const sat = new AMap.TileLayer.Satellite()
  632. this.map.add(sat)
  633. }
  634. } catch (layerErr) {
  635. console.warn('[job-create] satellite layer failed', layerErr)
  636. }
  637. // 添加工具栏
  638. try {
  639. AMap.plugin('AMap.ToolBar', () => {
  640. const toolbar = new AMap.ToolBar()
  641. if (this.map && typeof this.map.addControl === 'function') {
  642. this.map.addControl(toolbar)
  643. }
  644. })
  645. } catch (pluginErr) {
  646. console.warn('[job-create] toolbar plugin failed', pluginErr)
  647. }
  648. // 加载高德定位插件(异步加载)
  649. AMap.plugin('AMap.Geolocation', () => {
  650. this.geolocation = new AMap.Geolocation({
  651. enableHighAccuracy: true,
  652. timeout: 10000,
  653. maximumAge: 0, // 不使用缓存,每次都获取最新位置
  654. convert: true, // 自动偏移坐标,偏移后的坐标为高德坐标
  655. showButton: false,
  656. showMarker: false,
  657. showCircle: false,
  658. panToLocation: false,
  659. zoomToAccuracy: false,
  660. // 优先使用浏览器定位,失败后使用IP定位
  661. noIpLocate: 0,
  662. // 使用精确定位
  663. GeoLocationFirst: true
  664. })
  665. console.log('[job-create] 高德定位插件加载完成')
  666. // 插件加载完成后立即尝试定位
  667. this.tryAutoLocation()
  668. })
  669. // 绑定地图点击事件
  670. if (this.map && typeof this.map.on === 'function') {
  671. this.map.on('click', e => {
  672. const lng = e.lnglat && (e.lnglat.lng || (e.lnglat.getLng && e.lnglat.getLng()))
  673. const lat = e.lnglat && (e.lnglat.lat || (e.lnglat.getLat && e.lnglat.getLat()))
  674. if (lng == null || lat == null) return
  675. this.onMapClick({ lng, lat })
  676. })
  677. }
  678. // 地图初始化完成后,如果已选择设备,则开始轮询实时位置
  679. this.setupRealtimePolling()
  680. }
  681. // 创建地图(使用默认中心点)
  682. console.log('[job-create] 创建地图使用默认中心点:', defaultCenter)
  683. createMapWithCenter(defaultCenter)
  684. }
  685. createWhenReady()
  686. },
  687. // 自动定位(插件加载完成后调用)
  688. tryAutoLocation() {
  689. console.log('[job-create] 开始自动定位...')
  690. this._getCurrentLocation(
  691. res => {
  692. console.log('[job-create] 自动定位成功:', res)
  693. const { longitude, latitude } = res || {}
  694. if (longitude != null && latitude != null) {
  695. console.log('[job-create] 使用定位坐标:', [longitude, latitude])
  696. this._centerMapToLngLat(longitude, latitude, 16)
  697. uni.showToast({
  698. title: '已定位到您的位置',
  699. icon: 'success',
  700. duration: 2000
  701. })
  702. } else {
  703. console.warn('[job-create] 定位返回坐标无效')
  704. }
  705. },
  706. err => {
  707. console.warn('[job-create] 自动定位失败:', err)
  708. // 不显示错误提示,避免干扰用户
  709. }
  710. )
  711. },
  712. // 尝试获取设备定位并居中地图(优先使用 uni.getLocation,回退到 navigator 或模拟点)
  713. _getDeviceLocationAndCenter() {
  714. const doCenter = (lng, lat) => {
  715. if (!lng && lng !== 0) return
  716. if (!lat && lat !== 0) return
  717. this._centerMapToLngLat(lng, lat, 18)
  718. // 在当前位置添加一个简单标记(不影响现有图层)
  719. try {
  720. if (this.map && typeof AMap !== 'undefined' && AMap.Marker) {
  721. new AMap.Marker({
  722. position: [lng, lat],
  723. map: this.map
  724. })
  725. }
  726. } catch (err) {
  727. // eslint-disable-next-line no-console
  728. console.warn('[job-create] add marker failed', err)
  729. }
  730. }
  731. // 使用高德定位
  732. this._getCurrentLocation(
  733. res => {
  734. console.log("当前定位", res);
  735. const { longitude, latitude } = res || {}
  736. if (longitude != null && latitude != null) {
  737. doCenter(longitude, latitude)
  738. } else {
  739. const p = this.getMapCenterPoint() || mockCurrentPoint(0)
  740. doCenter(p.lng, p.lat)
  741. }
  742. },
  743. () => {
  744. const p = this.getMapCenterPoint() || mockCurrentPoint(0)
  745. doCenter(p.lng, p.lat)
  746. }
  747. )
  748. // 最后回退到地图中心或模拟点
  749. const p = this.getMapCenterPoint() || mockCurrentPoint(0)
  750. doCenter(p.lng, p.lat)
  751. },
  752. // 将地图居中到指定经纬度并设置缩放(安全调用)
  753. _centerMapToLngLat(lng, lat, zoom = 18) {
  754. if (!this.map) return
  755. try {
  756. if (typeof this.map.setCenter === 'function') {
  757. this.map.setCenter([lng, lat])
  758. }
  759. if (typeof this.map.setZoom === 'function' && typeof zoom === 'number') {
  760. this.map.setZoom(zoom)
  761. }
  762. } catch (err) {
  763. // eslint-disable-next-line no-console
  764. console.warn('[job-create] center map failed', err)
  765. }
  766. },
  767. // AMap 加载由页面顶部的全局 callback `mapInit` 与 `loadScript()` 管理
  768. // 使用高德定位获取当前位置
  769. _getCurrentLocation(successCallback, failCallback, retryCount = 0) {
  770. if (!this.geolocation) {
  771. // 如果还未初始化,等待一段时间后重试,最多重试5次
  772. if (retryCount < 5) {
  773. console.log(`[job-create] 高德定位未初始化,${retryCount + 1}秒后重试...`)
  774. setTimeout(() => {
  775. this._getCurrentLocation(successCallback, failCallback, retryCount + 1)
  776. }, 1000)
  777. return
  778. } else {
  779. console.warn('[job-create] 高德定位未初始化,重试失败')
  780. if (failCallback) failCallback(new Error('高德定位未初始化'))
  781. return
  782. }
  783. }
  784. console.log('[job-create] 开始调用高德定位 getCurrentPosition...')
  785. this.geolocation.getCurrentPosition((status, result) => {
  786. console.log('[job-create] 定位回调 status:', status, 'result:', result)
  787. if (status === 'complete') {
  788. const { lng, lat } = result.position
  789. console.log('[job-create] 高德定位成功:', { lng, lat })
  790. if (successCallback) {
  791. successCallback({
  792. longitude: lng,
  793. latitude: lat
  794. })
  795. }
  796. } else {
  797. console.error('[job-create] 高德定位失败:', result)
  798. let errorMsg = '定位失败'
  799. let errorDetail = ''
  800. switch(result.info) {
  801. case 'FAILED':
  802. errorMsg = '定位失败,请检查网络连接'
  803. errorDetail = '可能原因:网络问题或GPS信号弱'
  804. break
  805. case 'NOT_SUPPORTED':
  806. errorMsg = '浏览器不支持定位功能'
  807. errorDetail = '请使用支持地理定位的现代浏览器'
  808. break
  809. case 'PERMISSION_DENIED':
  810. errorMsg = '定位权限被拒绝'
  811. errorDetail = 'HTTPS环境下需要用户授权定位权限,HTTP环境下浏览器会直接拒绝'
  812. break
  813. case 'PERMISSION_GRANTED':
  814. errorMsg = '定位权限已获取但定位失败'
  815. errorDetail = '可能是GPS信号问题'
  816. break
  817. case 'TIMEOUT':
  818. errorMsg = '定位请求超时'
  819. errorDetail = '请检查网络连接或GPS信号'
  820. break
  821. default:
  822. errorMsg = `定位失败: ${result.info}`
  823. errorDetail = result.message || ''
  824. }
  825. console.warn('[job-create] 定位失败详情:', errorMsg, errorDetail)
  826. if (failCallback) {
  827. failCallback({
  828. code: result.info,
  829. message: errorMsg,
  830. detail: errorDetail
  831. })
  832. }
  833. }
  834. })
  835. },
  836. // 从地图获取中心点(回退到模拟坐标)
  837. getMapCenterPoint() {
  838. if (this.map && typeof this.map.getCenter === 'function') {
  839. const c = this.map.getCenter()
  840. // AMap 返回对象通常包含 lng/lat
  841. return {
  842. lng: c.lng || (c.lng === 0 ? 0 : c.getLng && c.getLng()),
  843. lat: c.lat || (c.lat === 0 ? 0 : c.getLat && c.getLat()),
  844. timestamp: Date.now()
  845. }
  846. }
  847. return null
  848. },
  849. // ---------- end AMap ----------
  850. // 区域类型与路线类型选择
  851. selectAreaType(val) {
  852. this.selectedAreaType = val
  853. const a = this.areaTypes.find(item => item.value === val)
  854. if (a && a.routes && a.routes.length) {
  855. this.selectedRouteType = a.routes[0].value
  856. }
  857. this.jobState.areaType = this.selectedAreaType
  858. this.jobState.routeType = this.selectedRouteType
  859. },
  860. selectRouteType(val) {
  861. this.selectedRouteType = val
  862. this.jobState.routeType = val
  863. },
  864. // 模式切换
  865. switchMode(val) {
  866. this.mode = val
  867. },
  868. // ===================== 设备实时位置轮询(参考 job-detail) =====================
  869. setupRealtimePolling() {
  870. // 仅 Step2 打点建模时需要实时位置
  871. if (this.currentStep !== 2) return
  872. const deviceId = this.jobState.machineId || this.jobState.machineCode
  873. if (!deviceId) return
  874. if (!this.amapLoaded || !this.map) return
  875. // 避免重复开启
  876. if (this.realtimeTimer) return
  877. // 立刻拉一次
  878. this.fetchRealtimeAndUpdate()
  879. this.realtimeTimer = setInterval(() => {
  880. this.fetchRealtimeAndUpdate()
  881. }, 3000)
  882. },
  883. clearRealtimePolling() {
  884. if (this.realtimeTimer) {
  885. clearInterval(this.realtimeTimer)
  886. this.realtimeTimer = null
  887. }
  888. this.polling = false
  889. },
  890. async fetchRealtimeAndUpdate() {
  891. try {
  892. const deviceId = this.jobState.machineCode
  893. if (!deviceId) return
  894. this.polling = true
  895. const res = await getRealtimeData(deviceId)
  896. const payload = res && res.data && (res.data.data || res.data)
  897. if (!payload) return
  898. const reportTime = payload.reportTime
  899. if (reportTime && this.lastReportTime && reportTime < this.lastReportTime) {
  900. return
  901. }
  902. if (reportTime) this.lastReportTime = reportTime
  903. const pt = payload.currentPoint
  904. if (!pt || pt.x == null || pt.y == null) return
  905. const lngLat = [pt.x, pt.y]
  906. this.latestRealtimeLngLat = lngLat
  907. this.updateRealtimeMarker(lngLat)
  908. // 轻量跟随:视野中心跟随车,不频繁 fitView
  909. try {
  910. if (this.map && typeof this.map.setCenter === 'function') {
  911. this.map.setCenter(lngLat)
  912. }
  913. } catch (e) {}
  914. } catch (e) {
  915. // eslint-disable-next-line no-console
  916. console.warn('[job-create] fetchRealtimeAndUpdate failed', e)
  917. } finally {
  918. this.polling = false
  919. }
  920. },
  921. updateRealtimeMarker(lngLat) {
  922. if (!this.map || !this.amapLoaded) return
  923. if (!lngLat || lngLat.length !== 2) return
  924. if (!this.realtimeMarker) {
  925. this.realtimeMarker = new AMap.Marker({
  926. map: this.map,
  927. position: lngLat
  928. })
  929. } else {
  930. this.realtimeMarker.setPosition(lngLat)
  931. }
  932. },
  933. // 新增点(使用模拟坐标/地图中心点)
  934. addPoint() {
  935. // Step2 的“新增点”需要使用设备实时位置:
  936. // - 轮询拿到的 latestRealtimeLngLat 优先
  937. // - 回退到地图中心点(手动拖拽视野时)
  938. // - 再回退到 mock
  939. const realtimeLngLat = this.latestRealtimeLngLat
  940. const realtimePoint = realtimeLngLat && realtimeLngLat.length === 2
  941. ? { lng: realtimeLngLat[0], lat: realtimeLngLat[1], timestamp: Date.now() }
  942. : null
  943. // 回退:地图中心点
  944. let centerPoint = null
  945. if (this.amapLoaded && this.map) {
  946. centerPoint = this.getMapCenterPoint()
  947. }
  948. const fallbackPoint = centerPoint || mockCurrentPoint(0)
  949. const point = realtimePoint || fallbackPoint
  950. if (this.mode === 'area') {
  951. this.onMapClick({ lng: point.lng, lat: point.lat })
  952. } else if (this.mode === 'obstacle') {
  953. this.currentObstacle.push(point)
  954. // 添加障碍物标记
  955. this.addObstacleMarker(point, this.jobState.obstacles.length, this.currentObstacle.length - 1)
  956. } else if (this.mode === 'return') {
  957. if (this.jobState.returnPoint) {
  958. uni.showModal({
  959. title: '覆盖返航点',
  960. content: '已存在返航点,是否覆盖为当前设备位置?',
  961. success: res => {
  962. if (res.confirm) {
  963. this.jobState.returnPoint = point
  964. // 更新返航点标记
  965. this.updateReturnMarker(point)
  966. }
  967. }
  968. })
  969. } else {
  970. this.jobState.returnPoint = point
  971. // 添加返航点标记
  972. this.updateReturnMarker(point)
  973. }
  974. }
  975. },
  976. // 撤销点
  977. undoPoint() {
  978. if (!this.canUndo) return
  979. if (this.mode === 'area') {
  980. // if (this.selectedAreaType === 'loopArea') {
  981. // 删除最后一个点,同时删除对应 draggable marker
  982. const lastIdx = this.jobState.areaPoints.length - 1
  983. if (lastIdx >= 0) {
  984. this.jobState.areaPoints.pop()
  985. const m = this.loopMarkers.pop()
  986. if (m && typeof m.setMap === 'function') {
  987. try { m.setMap(null) } catch (e) {}
  988. }
  989. // 更新 polygon 或清除
  990. if (this.jobState.areaPoints.length >= 3) {
  991. this.recomputeLoopPolygon()
  992. } else {
  993. if (this.loopPolygon && typeof this.loopPolygon.setMap === 'function') {
  994. try { this.loopPolygon.setMap(null) } catch (e) {}
  995. }
  996. this.loopPolygon = null
  997. }
  998. }
  999. // }
  1000. // else {
  1001. // // 非回字形:删除最后一个点,并同步删除最后一个 marker + 重绘 polygon
  1002. // const lastIdx = this.jobState.areaPoints.length - 1
  1003. // if (lastIdx >= 0) {
  1004. // this.jobState.areaPoints.pop()
  1005. // const m = this.markers && this.markers.length ? this.markers.pop() : null
  1006. // if (m && typeof m.setMap === 'function') {
  1007. // try { m.setMap(null) } catch (e) {}
  1008. // }
  1009. // }
  1010. // if (this.jobState.areaPoints.length >= 3) {
  1011. // this.drawAreaPolygon()
  1012. // } else if (this.areaPolygon) {
  1013. // try { this.areaPolygon.setMap(null) } catch (e) {}
  1014. // this.areaPolygon = null
  1015. // }
  1016. // }
  1017. } else if (this.mode === 'obstacle') {
  1018. this.currentObstacle.pop()
  1019. // 删除最后一个障碍物标记
  1020. this.removeLastObstacleMarker()
  1021. } else if (this.mode === 'return') {
  1022. this.jobState.returnPoint = null
  1023. // 删除返航点标记
  1024. this.clearReturnMarker()
  1025. }
  1026. },
  1027. // 完成当前障碍物
  1028. finishCurrentObstacle() {
  1029. if (!this.currentObstacle.length) return
  1030. this.jobState.obstacles.push([...this.currentObstacle])
  1031. this.currentObstacle = []
  1032. uni.showToast({
  1033. title: '已保存一组障碍物',
  1034. icon: 'success'
  1035. })
  1036. },
  1037. // 将“录入中”的障碍物也并入 jobState.obstacles(用于步骤切换/提交前兜底)
  1038. flushCurrentObstacle() {
  1039. if (this.currentObstacle && this.currentObstacle.length) {
  1040. this.jobState.obstacles.push([...this.currentObstacle])
  1041. this.currentObstacle = []
  1042. }
  1043. },
  1044. // 步骤导航
  1045. prevStep() {
  1046. if (this.currentStep === 1) return
  1047. this.currentStep -= 1
  1048. // 离开 Step2 时停止轮询,避免后台持续请求
  1049. if (this.currentStep !== 2) {
  1050. this.clearRealtimePolling()
  1051. }
  1052. },
  1053. nextStep() {
  1054. // Step1 校验:区域类型与路线类型必选
  1055. if (this.currentStep === 1) {
  1056. if (!this.selectedAreaType || !this.selectedRouteType) {
  1057. uni.showToast({
  1058. title: '请选择作业区域类型和路线类型',
  1059. icon: 'none'
  1060. })
  1061. return
  1062. }
  1063. this.jobState.areaType = this.selectedAreaType
  1064. this.jobState.routeType = this.selectedRouteType
  1065. }
  1066. // Step2 校验:作业区域点 / 返航点
  1067. if (this.currentStep === 2) {
  1068. if (this.jobState.areaPoints.length < 3) {
  1069. uni.showToast({
  1070. title: '作业区域点至少需要 3 个',
  1071. icon: 'none'
  1072. })
  1073. return
  1074. }
  1075. // 离开打点页前,把“录入中”的障碍物也保存下来,避免忘记点“完成当前障碍物”
  1076. this.flushCurrentObstacle()
  1077. if (!this.jobState.returnPoint) {
  1078. uni.showToast({
  1079. title: '请先设置返航点',
  1080. icon: 'none'
  1081. })
  1082. return
  1083. }
  1084. }
  1085. // Step3 校验:需存在作业区域点
  1086. if (this.currentStep === 3) {
  1087. if (!this.jobState.areaPoints.length) {
  1088. uni.showToast({
  1089. title: '请先在上一步记录作业区域点',
  1090. icon: 'none'
  1091. })
  1092. return
  1093. }
  1094. }
  1095. if (this.currentStep < 4) {
  1096. this.currentStep += 1
  1097. // 进入 Step2 时开启轮询(地图可能已初始化)
  1098. if (this.currentStep === 2) {
  1099. this.setupRealtimePolling()
  1100. } else {
  1101. // 离开 Step2 时关闭轮询
  1102. this.clearRealtimePolling()
  1103. }
  1104. }
  1105. },
  1106. // 起点选择
  1107. setStartIndex(index) {
  1108. if (!this.jobState.areaPoints.length) return
  1109. this.jobState.startPointIndex = index
  1110. },
  1111. prevStart() {
  1112. if (!this.canChangeStart) return
  1113. const total = this.jobState.areaPoints.length
  1114. this.jobState.startPointIndex =
  1115. (this.jobState.startPointIndex - 1 + total) % total
  1116. },
  1117. nextStart() {
  1118. if (!this.canChangeStart) return
  1119. const total = this.jobState.areaPoints.length
  1120. this.jobState.startPointIndex =
  1121. (this.jobState.startPointIndex + 1) % total
  1122. },
  1123. // 手动定位
  1124. async manualLocation() {
  1125. if (this.locating) return
  1126. this.locating = true
  1127. const doCenter = (lng, lat) => {
  1128. if (!lng && lng !== 0) return
  1129. if (!lat && lat !== 0) return
  1130. this._centerMapToLngLat(lng, lat, 18)
  1131. uni.showToast({
  1132. title: '已定位到您的位置',
  1133. icon: 'success',
  1134. duration: 2000
  1135. })
  1136. }
  1137. try {
  1138. // 检查是否为HTTPS环境
  1139. const isSecureContext = window.isSecureContext || window.location.protocol === 'https:'
  1140. if (!isSecureContext) {
  1141. console.warn('[job-create] 非HTTPS环境,浏览器可能拒绝定位请求')
  1142. uni.showModal({
  1143. title: '定位提示',
  1144. content: '当前为HTTP环境,浏览器可能拒绝定位请求。建议使用HTTPS访问或使用IP定位。',
  1145. showCancel: false
  1146. })
  1147. }
  1148. // 使用高德定位
  1149. await new Promise((resolve, reject) => {
  1150. this._getCurrentLocation(
  1151. res => {
  1152. const { longitude, latitude } = res || {}
  1153. if (longitude != null && latitude != null) {
  1154. doCenter(longitude, latitude)
  1155. resolve()
  1156. } else {
  1157. reject(new Error('无效坐标'))
  1158. }
  1159. },
  1160. reject
  1161. )
  1162. })
  1163. } catch (err) {
  1164. console.error('[job-create] 手动定位失败:', err)
  1165. let errorMsg = '定位失败'
  1166. let showDetail = false
  1167. if (err.message) {
  1168. errorMsg = err.message
  1169. }
  1170. if (err.detail) {
  1171. showDetail = true
  1172. }
  1173. if (showDetail) {
  1174. uni.showModal({
  1175. title: errorMsg,
  1176. content: err.detail || '请检查浏览器定位权限设置,或确保使用HTTPS访问',
  1177. showCancel: false
  1178. })
  1179. } else {
  1180. uni.showToast({
  1181. title: errorMsg,
  1182. icon: 'none',
  1183. duration: 3000
  1184. })
  1185. }
  1186. } finally {
  1187. this.locating = false
  1188. }
  1189. },
  1190. // 提交作业
  1191. async submitJob() {
  1192. if (!this.jobState.jobName) {
  1193. uni.showToast({
  1194. title: '请填写作业名称',
  1195. icon: 'none'
  1196. })
  1197. return
  1198. }
  1199. if (!this.jobState.fieldId) {
  1200. uni.showToast({
  1201. title: '请填写地块ID',
  1202. icon: 'none'
  1203. })
  1204. return
  1205. }
  1206. if (!this.jobState.pathWidth) {
  1207. uni.showToast({
  1208. title: '请填写路径宽度',
  1209. icon: 'none'
  1210. })
  1211. return
  1212. }
  1213. if (this.jobState.areaPoints.length < 3) {
  1214. uni.showToast({
  1215. title: '作业区域点至少需要 3 个',
  1216. icon: 'none'
  1217. })
  1218. return
  1219. }
  1220. // 提交前兜底:把“录入中”的障碍物也并入 obstacles
  1221. this.flushCurrentObstacle()
  1222. // 将高德坐标转换为WGS84坐标
  1223. const convertedAreaPoints = coordinateUtils.convertPointsToWgs84(this.jobState.areaPoints)
  1224. const convertedObstacles = this.jobState.obstacles.map(obstacleGroup =>
  1225. coordinateUtils.convertPointsToWgs84(obstacleGroup)
  1226. )
  1227. const convertedReturnPoint = this.jobState.returnPoint ?
  1228. coordinateUtils.convertPointToWgs84(this.jobState.returnPoint) : undefined
  1229. // 映射 areaType 到数字
  1230. const areaTypeMap = {
  1231. 'loopArea': 1, // 回字形
  1232. 'bowArea': 2, // 弓字形
  1233. 'customArea': 3, // 自定义
  1234. 'ridgeArea': 4 // 垄沟
  1235. }
  1236. console.log("this.jobState",this.jobState);
  1237. const payload = {
  1238. // deviceId: this.jobState.machineCode,
  1239. deviceId: this.jobState.machineId,
  1240. fieldId: parseInt(this.jobState.fieldId),
  1241. taskName: this.jobState.jobName,
  1242. areaType: areaTypeMap[this.jobState.areaType] || 1,
  1243. waypoints: convertedAreaPoints.map(p => ({ lng: p.lng, lat: p.lat })),
  1244. obstacles: convertedObstacles.flat().map(p => ({ lng: p.lng, lat: p.lat })),
  1245. returnPoint: convertedReturnPoint ? { lng: convertedReturnPoint.lng, lat: convertedReturnPoint.lat } : undefined,
  1246. pathWidth: parseInt(this.jobState.pathWidth)
  1247. }
  1248. console.log("payload",payload);
  1249. this.submitting = true
  1250. uni.showLoading({ title: '提交中...' })
  1251. try {
  1252. const res = await createJob(payload)
  1253. console.log("res收到尽快发货",res);
  1254. const { data } = res || {}
  1255. if (data && data.code === 200) {
  1256. uni.showToast({
  1257. title: '作业创建成功',
  1258. icon: 'success'
  1259. })
  1260. setTimeout(() => {
  1261. uni.navigateBack()
  1262. }, 800)
  1263. } else {
  1264. uni.showToast({
  1265. title: (data && data.msg) || '提交失败',
  1266. icon: 'none'
  1267. })
  1268. }
  1269. } catch (err) {
  1270. console.error('创建作业失败', err)
  1271. uni.showToast({
  1272. title: '网络异常或接口未就绪',
  1273. icon: 'none'
  1274. })
  1275. } finally {
  1276. this.submitting = false
  1277. uni.hideLoading()
  1278. }
  1279. },
  1280. // 区域编辑逻辑(支持所有区域类型)
  1281. // - 点击地图依次记录点(或替换已选点)
  1282. // - 回字形区域使用可拖拽 Marker,其他区域使用普通 Marker
  1283. // - 点击某个点可以进入“替换模式”,下一次地图点击会替换该点
  1284. onMapClick({ lng, lat } = {}) {
  1285. if (!lng && lng !== 0) return
  1286. if (!lat && lat !== 0) return
  1287. // 确保在区域编辑模式下
  1288. if (this.mode !== 'area') return
  1289. const newPoint = { lng, lat, timestamp: Date.now() }
  1290. // 回字形区域特殊处理(支持拖拽和替换)
  1291. // 替换模式下替换指定点
  1292. if (this.loopReplaceIndex != null && this.loopReplaceIndex >= 0 && this.loopReplaceIndex < this.jobState.areaPoints.length) {
  1293. this.jobState.areaPoints.splice(this.loopReplaceIndex, 1, newPoint)
  1294. const m = this.loopMarkers[this.loopReplaceIndex]
  1295. if (m && typeof m.setPosition === 'function') {
  1296. try { m.setPosition([lng, lat]) } catch (e) {}
  1297. }
  1298. this.loopReplaceIndex = null
  1299. if (this.jobState.areaPoints.length >= 3) this.recomputeLoopPolygon()
  1300. return
  1301. }
  1302. // 正常添加点
  1303. this.jobState.areaPoints.push(newPoint)
  1304. const idx = this.jobState.areaPoints.length - 1
  1305. this.createOrUpdateLoopMarker(idx, newPoint)
  1306. if (this.jobState.areaPoints.length >= 3) {
  1307. this.recomputeLoopPolygon()
  1308. }
  1309. // }
  1310. },
  1311. createOrUpdateLoopMarker(index, point) {
  1312. if (!this.map || typeof AMap === 'undefined') return
  1313. const pos = [point.lng, point.lat]
  1314. let marker = this.loopMarkers[index]
  1315. if (marker) {
  1316. try { marker.setPosition(pos) } catch (e) {}
  1317. return
  1318. }
  1319. // Use smaller icon size
  1320. let icon = null
  1321. try {
  1322. icon = new AMap.Icon({
  1323. image: "static/icons/poi-marker-default.png",
  1324. size: new AMap.Size(20, 28),
  1325. imageSize: new AMap.Size(20, 28)
  1326. })
  1327. } catch (e) {
  1328. icon = "static/icons/poi-marker-default.png"
  1329. }
  1330. marker = new AMap.Marker({
  1331. position: pos,
  1332. map: this.map,
  1333. draggable: true,
  1334. icon,
  1335. offset: new AMap.Pixel(-10, -28)
  1336. })
  1337. // add simple label showing index (P1, P2...)
  1338. try {
  1339. const labelContent = `<div class="p-marker-label">P${index + 1}</div>`
  1340. if (typeof marker.setLabel === 'function') {
  1341. marker.setLabel({
  1342. content: labelContent,
  1343. offset: new AMap.Pixel(10, -36)
  1344. })
  1345. } else {
  1346. marker.label = { content: labelContent }
  1347. }
  1348. } catch (e) {}
  1349. // drag end -> update point and polygon
  1350. marker.on('dragend', e => {
  1351. const p = marker.getPosition()
  1352. const lngv = p.lng || (p.getLng && p.getLng())
  1353. const latv = p.lat || (p.getLat && p.getLat())
  1354. if (lngv == null || latv == null) return
  1355. // Use Vue.set / $set to ensure reactivity for array index assignment
  1356. if (typeof this.$set === 'function') {
  1357. this.$set(this.jobState.areaPoints, index, { lng: lngv, lat: latv, timestamp: Date.now() })
  1358. } else {
  1359. this.jobState.areaPoints[index] = { lng: lngv, lat: latv, timestamp: Date.now() }
  1360. }
  1361. if (this.jobState.areaPoints.length >= 3) this.recomputeLoopPolygon()
  1362. })
  1363. // click -> enter replace mode for this index
  1364. marker.on('click', () => {
  1365. this.loopReplaceIndex = index
  1366. uni.showToast({ title: `已选中 P${index + 1},下一次点击将替换该点`, icon: 'none' })
  1367. })
  1368. this.loopMarkers[index] = marker
  1369. // refresh labels for all markers to keep numbering consistent
  1370. this.refreshLoopMarkerLabels()
  1371. },
  1372. recomputeLoopPolygon() {
  1373. if (!this.map) return
  1374. if (!this.jobState.areaPoints || this.jobState.areaPoints.length < 3) {
  1375. if (this.loopPolygon && typeof this.loopPolygon.setMap === 'function') {
  1376. try { this.loopPolygon.setMap(null) } catch (e) {}
  1377. }
  1378. this.loopPolygon = null
  1379. return
  1380. }
  1381. // Outer path: ensure order as [ [lng,lat], ... ]
  1382. const outer = this.jobState.areaPoints.map(p => [p.lng, p.lat])
  1383. try {
  1384. if (this.loopPolygon) {
  1385. this.loopPolygon.setPath(outer)
  1386. } else {
  1387. this.loopPolygon = new AMap.Polygon({
  1388. map: this.map,
  1389. path: outer,
  1390. strokeColor: '#3bb44a',
  1391. strokeWeight: 2,
  1392. fillColor: '#3bb44a',
  1393. fillOpacity: 0.15
  1394. })
  1395. }
  1396. } catch (err) {
  1397. // eslint-disable-next-line no-console
  1398. console.warn('[job-create] recompute loop polygon failed', err)
  1399. }
  1400. },
  1401. refreshLoopMarkerLabels() {
  1402. if (!this.loopMarkers || !this.loopMarkers.length) return
  1403. this.loopMarkers.forEach((m, i) => {
  1404. try {
  1405. const content = `<div class="p-marker-label">P${i + 1}</div>`
  1406. if (typeof m.setLabel === 'function') {
  1407. m.setLabel({ content, offset: new AMap.Pixel(10, -36) })
  1408. } else if (m.label) {
  1409. m.label.content = content
  1410. }
  1411. } catch (e) {}
  1412. })
  1413. },
  1414. // 清空所有 loop 图形(用于删除区域)
  1415. clearLoopGraphics() {
  1416. if (this.loopMarkers && this.loopMarkers.length) {
  1417. this.loopMarkers.forEach(m => {
  1418. try { m.setMap(null) } catch (e) {}
  1419. })
  1420. }
  1421. this.loopMarkers = []
  1422. if (this.loopPolygon && typeof this.loopPolygon.setMap === 'function') {
  1423. try { this.loopPolygon.setMap(null) } catch (e) {}
  1424. }
  1425. this.loopPolygon = null
  1426. this.loopReplaceIndex = null
  1427. },
  1428. // 删除某一个点(根据需求:删除后清空整个区域)
  1429. deleteAreaPoints() {
  1430. this.jobState.areaPoints = []
  1431. this.clearLoopGraphics()
  1432. },
  1433. // 辅助显示
  1434. formatPoint(p) {
  1435. if (!p) return '--'
  1436. return `${p.lng.toFixed(5)}, ${p.lat.toFixed(5)}`
  1437. },
  1438. formatPointTime(ts) {
  1439. if (!ts) return ''
  1440. const d = new Date(ts)
  1441. const h = `${d.getHours()}`.padStart(2, '0')
  1442. const m = `${d.getMinutes()}`.padStart(2, '0')
  1443. const s = `${d.getSeconds()}`.padStart(2, '0')
  1444. return `${h}:${m}:${s}`
  1445. },
  1446. // 添加障碍物标记
  1447. addObstacleMarker(point, obstacleGroupIndex, pointIndex) {
  1448. if (!this.map || !this.amapLoaded || typeof AMap === 'undefined') return
  1449. try {
  1450. const pos = [point.lng, point.lat]
  1451. // 创建障碍物图标(使用不同颜色区分)
  1452. let icon = null
  1453. try {
  1454. icon = new AMap.Icon({
  1455. image: "static/icons/poi-marker-default.png",
  1456. size: new AMap.Size(16, 22),
  1457. imageSize: new AMap.Size(16, 22)
  1458. })
  1459. } catch (e) {
  1460. icon = "static/icons/poi-marker-default.png"
  1461. }
  1462. const marker = new AMap.Marker({
  1463. position: pos,
  1464. map: this.map,
  1465. icon,
  1466. offset: new AMap.Pixel(-8, -22)
  1467. })
  1468. // 添加标签显示障碍物编号
  1469. try {
  1470. const labelContent = `<div class="obstacle-marker-label">O${obstacleGroupIndex + 1}-${pointIndex + 1}</div>`
  1471. if (typeof marker.setLabel === 'function') {
  1472. marker.setLabel({
  1473. content: labelContent,
  1474. offset: new AMap.Pixel(8, -28)
  1475. })
  1476. }
  1477. } catch (e) {}
  1478. // 保存标记到数组
  1479. if (!this.obstacleMarkers[obstacleGroupIndex]) {
  1480. this.obstacleMarkers[obstacleGroupIndex] = []
  1481. }
  1482. this.obstacleMarkers[obstacleGroupIndex].push(marker)
  1483. } catch (err) {
  1484. console.warn('[job-create] add obstacle marker failed', err)
  1485. }
  1486. },
  1487. // 删除最后一个障碍物标记
  1488. removeLastObstacleMarker() {
  1489. const currentGroupIndex = this.jobState.obstacles.length
  1490. if (this.obstacleMarkers[currentGroupIndex] && this.obstacleMarkers[currentGroupIndex].length > 0) {
  1491. const marker = this.obstacleMarkers[currentGroupIndex].pop()
  1492. if (marker && typeof marker.setMap === 'function') {
  1493. try {
  1494. marker.setMap(null)
  1495. } catch (e) {}
  1496. }
  1497. }
  1498. },
  1499. // 更新返航点标记
  1500. updateReturnMarker(point) {
  1501. if (!this.map || !this.amapLoaded || typeof AMap === 'undefined') return
  1502. try {
  1503. const pos = [point.lng, point.lat]
  1504. // 如果已存在返航点标记,先删除
  1505. this.clearReturnMarker()
  1506. // 创建返航点图标(使用特殊颜色)
  1507. let icon = null
  1508. try {
  1509. icon = new AMap.Icon({
  1510. image: "static/icons/poi-marker-default.png",
  1511. size: new AMap.Size(20, 28),
  1512. imageSize: new AMap.Size(20, 28)
  1513. })
  1514. } catch (e) {
  1515. icon = "static/icons/poi-marker-default.png"
  1516. }
  1517. this.returnMarker = new AMap.Marker({
  1518. position: pos,
  1519. map: this.map,
  1520. icon,
  1521. offset: new AMap.Pixel(-10, -28)
  1522. })
  1523. // 添加标签
  1524. try {
  1525. const labelContent = '<div class="return-marker-label">返航点</div>'
  1526. if (typeof this.returnMarker.setLabel === 'function') {
  1527. this.returnMarker.setLabel({
  1528. content: labelContent,
  1529. offset: new AMap.Pixel(10, -36)
  1530. })
  1531. }
  1532. } catch (e) {}
  1533. } catch (err) {
  1534. console.warn('[job-create] update return marker failed', err)
  1535. }
  1536. },
  1537. // 清除返航点标记
  1538. clearReturnMarker() {
  1539. if (this.returnMarker && typeof this.returnMarker.setMap === 'function') {
  1540. try {
  1541. this.returnMarker.setMap(null)
  1542. } catch (e) {}
  1543. }
  1544. this.returnMarker = null
  1545. },
  1546. // 清理所有标记(页面卸载时调用)
  1547. clearAllMarkers() {
  1548. // 清理作业区域标记
  1549. if (this.loopMarkers && this.loopMarkers.length) {
  1550. this.loopMarkers.forEach(m => {
  1551. try {
  1552. if (m && typeof m.setMap === 'function') {
  1553. m.setMap(null)
  1554. }
  1555. } catch (e) {}
  1556. })
  1557. this.loopMarkers = []
  1558. }
  1559. // 清理障碍物标记
  1560. if (this.obstacleMarkers && this.obstacleMarkers.length) {
  1561. this.obstacleMarkers.forEach(group => {
  1562. if (group && group.length) {
  1563. group.forEach(m => {
  1564. try {
  1565. if (m && typeof m.setMap === 'function') {
  1566. m.setMap(null)
  1567. }
  1568. } catch (e) {}
  1569. })
  1570. }
  1571. })
  1572. this.obstacleMarkers = []
  1573. }
  1574. // 清理返航点标记
  1575. this.clearReturnMarker()
  1576. // 清理实时位置标记
  1577. if (this.realtimeMarker && typeof this.realtimeMarker.setMap === 'function') {
  1578. try {
  1579. this.realtimeMarker.setMap(null)
  1580. } catch (e) {}
  1581. this.realtimeMarker = null
  1582. }
  1583. // 清理多边形
  1584. if (this.loopPolygon && typeof this.loopPolygon.setMap === 'function') {
  1585. try {
  1586. this.loopPolygon.setMap(null)
  1587. } catch (e) {}
  1588. this.loopPolygon = null
  1589. }
  1590. }
  1591. }
  1592. }
  1593. </script>
  1594. <style scoped>
  1595. .page {
  1596. display: flex;
  1597. flex-direction: column;
  1598. min-height: 100vh;
  1599. background-color: #f6f9f7;
  1600. }
  1601. .header {
  1602. padding: 24rpx 28rpx 12rpx;
  1603. }
  1604. .title-row {
  1605. display: flex;
  1606. justify-content: space-between;
  1607. align-items: baseline;
  1608. margin-bottom: 12rpx;
  1609. }
  1610. .title {
  1611. font-size: 34rpx;
  1612. font-weight: 600;
  1613. color: #2c3e50;
  1614. }
  1615. .device-id {
  1616. font-size: 24rpx;
  1617. color: #8c9396;
  1618. }
  1619. .step-row {
  1620. display: flex;
  1621. padding: 10rpx 8rpx;
  1622. border-radius: 16rpx;
  1623. background-color: #eef6f0;
  1624. }
  1625. .step-item {
  1626. flex: 1;
  1627. display: flex;
  1628. align-items: center;
  1629. }
  1630. .step-index {
  1631. width: 36rpx;
  1632. height: 36rpx;
  1633. border-radius: 18rpx;
  1634. border: 2rpx solid #b0c4b8;
  1635. display: flex;
  1636. align-items: center;
  1637. justify-content: center;
  1638. font-size: 22rpx;
  1639. color: #7f8c8d;
  1640. margin-right: 10rpx;
  1641. }
  1642. .step-index.active {
  1643. background: linear-gradient(135deg, #3bb44a, #66cc6a);
  1644. color: #ffffff;
  1645. border-color: transparent;
  1646. }
  1647. .step-index.done {
  1648. background-color: #ffffff;
  1649. color: #3bb44a;
  1650. border-color: #3bb44a;
  1651. }
  1652. .step-texts {
  1653. display: flex;
  1654. flex-direction: column;
  1655. }
  1656. .step-title {
  1657. font-size: 24rpx;
  1658. color: #2c3e50;
  1659. }
  1660. .step-sub {
  1661. font-size: 20rpx;
  1662. color: #8c9396;
  1663. }
  1664. .content {
  1665. flex: 1;
  1666. padding: 10rpx 24rpx 130rpx;
  1667. box-sizing: border-box;
  1668. }
  1669. .step-block {
  1670. display: flex;
  1671. flex-direction: column;
  1672. gap: 18rpx;
  1673. }
  1674. /* 区域类型 & 路线类型选择卡片 */
  1675. .card.select-card {
  1676. background-color: #ffffff;
  1677. border-radius: 20rpx;
  1678. padding: 20rpx 22rpx 16rpx;
  1679. box-shadow: 0 4rpx 14rpx rgba(0, 0, 0, 0.03);
  1680. }
  1681. .select-title {
  1682. font-size: 26rpx;
  1683. font-weight: 600;
  1684. color: #2c3e50;
  1685. }
  1686. .select-sub {
  1687. margin-top: 6rpx;
  1688. font-size: 22rpx;
  1689. color: #8c9396;
  1690. line-height: 1.5;
  1691. }
  1692. .select-tabs {
  1693. margin-top: 14rpx;
  1694. display: flex;
  1695. flex-wrap: wrap;
  1696. gap: 12rpx;
  1697. }
  1698. .select-tab {
  1699. min-width: 46%;
  1700. padding: 14rpx 16rpx;
  1701. border-radius: 16rpx;
  1702. background-color: #f3f5f7;
  1703. box-sizing: border-box;
  1704. }
  1705. .select-tab.small {
  1706. min-width: 30%;
  1707. }
  1708. .select-tab-label {
  1709. font-size: 24rpx;
  1710. color: #2c3e50;
  1711. }
  1712. .select-tab-sub {
  1713. margin-top: 4rpx;
  1714. font-size: 20rpx;
  1715. color: #8c9396;
  1716. }
  1717. .select-tab.active {
  1718. background: linear-gradient(135deg, #3bb44a, #66cc6a);
  1719. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.26);
  1720. }
  1721. .select-tab.active .select-tab-label,
  1722. .select-tab.active .select-tab-sub {
  1723. color: #ffffff;
  1724. }
  1725. .map-card {
  1726. background-color: #ffffff;
  1727. border-radius: 20rpx;
  1728. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  1729. overflow: hidden;
  1730. }
  1731. .map-card.small .map-body {
  1732. height: 260rpx;
  1733. }
  1734. .map-header {
  1735. padding: 20rpx 22rpx 10rpx;
  1736. display: flex;
  1737. justify-content: space-between;
  1738. align-items: flex-start;
  1739. }
  1740. .map-header-actions {
  1741. margin-left: 20rpx;
  1742. }
  1743. .map-title {
  1744. font-size: 28rpx;
  1745. font-weight: 600;
  1746. color: #2c3e50;
  1747. }
  1748. .map-sub {
  1749. margin-top: 4rpx;
  1750. font-size: 22rpx;
  1751. color: #8c9396;
  1752. }
  1753. .map-body {
  1754. height: 320rpx;
  1755. background-color: #d3dce6;
  1756. display: flex;
  1757. align-items: center;
  1758. justify-content: center;
  1759. }
  1760. .map-placeholder {
  1761. font-size: 24rpx;
  1762. color: #ffffff;
  1763. text-align: center;
  1764. white-space: pre-line;
  1765. width: 100%;
  1766. }
  1767. /* AMap 容器样式(确保占满 map-body) */
  1768. #mapContainer {
  1769. width: 100%;
  1770. height: 100%;
  1771. }
  1772. .map-footer {
  1773. padding: 12rpx 18rpx 16rpx;
  1774. background-color: #f7faf8;
  1775. }
  1776. .map-hint {
  1777. font-size: 22rpx;
  1778. color: #8c9396;
  1779. }
  1780. .mode-card {
  1781. background-color: #ffffff;
  1782. border-radius: 20rpx;
  1783. padding: 18rpx 20rpx 14rpx;
  1784. box-shadow: 0 4rpx 14rpx rgba(0, 0, 0, 0.03);
  1785. }
  1786. .mode-title-row {
  1787. margin-bottom: 10rpx;
  1788. }
  1789. .mode-title {
  1790. font-size: 26rpx;
  1791. font-weight: 600;
  1792. color: #2c3e50;
  1793. }
  1794. .mode-sub {
  1795. margin-top: 4rpx;
  1796. font-size: 22rpx;
  1797. color: #8c9396;
  1798. }
  1799. .mode-tabs {
  1800. display: flex;
  1801. gap: 12rpx;
  1802. }
  1803. .mode-tab {
  1804. flex: 1;
  1805. padding: 12rpx 0;
  1806. border-radius: 30rpx;
  1807. background-color: #f3f5f7;
  1808. text-align: center;
  1809. font-size: 24rpx;
  1810. color: #666;
  1811. }
  1812. .mode-tab.active {
  1813. background: linear-gradient(135deg, #3bb44a, #66cc6a);
  1814. color: #ffffff;
  1815. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.3);
  1816. }
  1817. .panel-card {
  1818. background-color: #ffffff;
  1819. border-radius: 20rpx;
  1820. padding: 18rpx 20rpx 14rpx;
  1821. box-shadow: 0 4rpx 14rpx rgba(0, 0, 0, 0.03);
  1822. }
  1823. .panel-row {
  1824. display: flex;
  1825. gap: 12rpx;
  1826. }
  1827. .panel-row.center {
  1828. justify-content: space-between;
  1829. align-items: center;
  1830. }
  1831. .panel-desc {
  1832. margin-top: 8rpx;
  1833. font-size: 22rpx;
  1834. color: #8c9396;
  1835. }
  1836. .list-card {
  1837. background-color: #ffffff;
  1838. border-radius: 20rpx;
  1839. padding: 18rpx 20rpx 10rpx;
  1840. box-shadow: 0 4rpx 14rpx rgba(0, 0, 0, 0.03);
  1841. max-height: 420rpx;
  1842. }
  1843. .list-title-row {
  1844. margin-bottom: 6rpx;
  1845. }
  1846. .list-title {
  1847. font-size: 26rpx;
  1848. font-weight: 600;
  1849. color: #2c3e50;
  1850. }
  1851. .list-scroll {
  1852. max-height: 360rpx;
  1853. }
  1854. .list-group {
  1855. margin-top: 10rpx;
  1856. }
  1857. .list-group-header {
  1858. margin-bottom: 4rpx;
  1859. }
  1860. .list-group-title {
  1861. font-size: 24rpx;
  1862. color: #555;
  1863. }
  1864. .point-list {
  1865. margin-top: 4rpx;
  1866. }
  1867. .point-item {
  1868. padding: 8rpx 4rpx;
  1869. border-bottom: 1rpx solid #f0f0f0;
  1870. display: flex;
  1871. align-items: center;
  1872. }
  1873. .point-item.small {
  1874. padding-left: 20rpx;
  1875. }
  1876. .point-item.active {
  1877. background-color: #f0f9f2;
  1878. }
  1879. .point-label {
  1880. font-size: 22rpx;
  1881. color: #3bb44a;
  1882. margin-right: 8rpx;
  1883. }
  1884. .point-coord {
  1885. flex: 1;
  1886. font-size: 22rpx;
  1887. color: #333;
  1888. }
  1889. .point-time {
  1890. font-size: 20rpx;
  1891. color: #999;
  1892. }
  1893. .obstacle-item {
  1894. margin-top: 6rpx;
  1895. }
  1896. .obstacle-title {
  1897. font-size: 22rpx;
  1898. color: #666;
  1899. margin-bottom: 2rpx;
  1900. }
  1901. .empty-row {
  1902. padding: 12rpx 0;
  1903. font-size: 22rpx;
  1904. color: #999;
  1905. }
  1906. .start-index {
  1907. flex: 1;
  1908. align-items: center;
  1909. justify-content: center;
  1910. display: flex;
  1911. }
  1912. .start-index-text {
  1913. font-size: 26rpx;
  1914. color: #2c3e50;
  1915. }
  1916. .card.confirm-card {
  1917. padding: 22rpx 24rpx 10rpx;
  1918. }
  1919. .confirm-title {
  1920. font-size: 28rpx;
  1921. font-weight: 600;
  1922. color: #2c3e50;
  1923. margin-bottom: 12rpx;
  1924. }
  1925. .form-item {
  1926. margin-bottom: 16rpx;
  1927. }
  1928. .form-item.required .label::after {
  1929. content: '*';
  1930. color: #ff4d4f;
  1931. margin-left: 4rpx;
  1932. }
  1933. .label {
  1934. display: block;
  1935. font-size: 26rpx;
  1936. color: #555;
  1937. margin-bottom: 8rpx;
  1938. }
  1939. .input {
  1940. width: 100%;
  1941. height: 80rpx;
  1942. line-height: 80rpx;
  1943. padding: 14rpx 18rpx;
  1944. border-radius: 12rpx;
  1945. background-color: #f7f7f7;
  1946. font-size: 26rpx;
  1947. color: #333;
  1948. box-sizing: border-box;
  1949. }
  1950. .summary-row {
  1951. display: flex;
  1952. justify-content: space-between;
  1953. padding: 8rpx 0;
  1954. border-bottom: 1rpx solid #f0f0f0;
  1955. }
  1956. .summary-label {
  1957. font-size: 24rpx;
  1958. color: #777;
  1959. }
  1960. .summary-value {
  1961. font-size: 24rpx;
  1962. color: #333;
  1963. }
  1964. .tips-card {
  1965. padding: 20rpx 22rpx 16rpx;
  1966. }
  1967. .tips-title {
  1968. font-size: 26rpx;
  1969. color: #2c3e50;
  1970. font-weight: 600;
  1971. margin-bottom: 6rpx;
  1972. }
  1973. .tips-content text {
  1974. display: block;
  1975. font-size: 22rpx;
  1976. color: #666;
  1977. margin-top: 4rpx;
  1978. }
  1979. .footer {
  1980. position: fixed;
  1981. left: 0;
  1982. right: 0;
  1983. bottom: 0;
  1984. padding: 12rpx 26rpx 24rpx;
  1985. background-color: #ffffff;
  1986. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
  1987. display: flex;
  1988. gap: 12rpx;
  1989. box-sizing: border-box;
  1990. }
  1991. .btn {
  1992. flex: 1;
  1993. height: 84rpx;
  1994. line-height: 84rpx;
  1995. border-radius: 42rpx;
  1996. font-size: 28rpx;
  1997. }
  1998. .btn.primary {
  1999. background: linear-gradient(135deg, #3bb44a, #66cc6a);
  2000. color: #ffffff;
  2001. }
  2002. .btn.ghost {
  2003. background-color: #f4f5f7;
  2004. color: #555;
  2005. }
  2006. .btn:disabled {
  2007. opacity: 0.5;
  2008. }
  2009. .btn-location {
  2010. padding: 8rpx 16rpx;
  2011. border-radius: 20rpx;
  2012. background-color: #f0f9f2;
  2013. border: 1rpx solid #3bb44a;
  2014. font-size: 24rpx;
  2015. color: #3bb44a;
  2016. display: flex;
  2017. align-items: center;
  2018. justify-content: center;
  2019. min-width: 120rpx;
  2020. height: 56rpx;
  2021. box-sizing: border-box;
  2022. }
  2023. .btn-location-text {
  2024. font-size: 24rpx;
  2025. color: #3bb44a;
  2026. }
  2027. /* 任务标题行新增作业按钮样式(与详情页保持风格一致) */
  2028. .task-title-row {
  2029. display: flex;
  2030. justify-content: space-between;
  2031. align-items: center;
  2032. }
  2033. .task-title-left {
  2034. display: flex;
  2035. flex-direction: column;
  2036. }
  2037. .task-title-text {
  2038. font-size: 32rpx;
  2039. font-weight: 600;
  2040. color: #2c3e50;
  2041. }
  2042. .task-title-sub {
  2043. margin-top: 4rpx;
  2044. font-size: 22rpx;
  2045. color: #8c9396;
  2046. }
  2047. .task-add-btn {
  2048. width: 60rpx;
  2049. height: 60rpx;
  2050. border-radius: 30rpx;
  2051. background: linear-gradient(135deg, #3bb44a, #66cc6a);
  2052. display: flex;
  2053. align-items: center;
  2054. justify-content: center;
  2055. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.3);
  2056. }
  2057. .task-add-plus {
  2058. font-size: 40rpx;
  2059. color: #ffffff;
  2060. line-height: 1;
  2061. }
  2062. .p-marker-label {
  2063. background: rgba(59,180,74,0.95);
  2064. color: #fff;
  2065. padding: 2px 6px;
  2066. border-radius: 10px;
  2067. font-size: 18rpx;
  2068. line-height: 1;
  2069. }
  2070. .obstacle-marker-label {
  2071. background: rgba(255, 152, 0, 0.95);
  2072. color: #fff;
  2073. padding: 2px 6px;
  2074. border-radius: 10px;
  2075. font-size: 16rpx;
  2076. line-height: 1;
  2077. }
  2078. .return-marker-label {
  2079. background: rgba(33, 150, 243, 0.95);
  2080. color: #fff;
  2081. padding: 2px 8px;
  2082. border-radius: 10px;
  2083. font-size: 18rpx;
  2084. line-height: 1;
  2085. font-weight: 600;
  2086. }
  2087. </style>