You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
7.8 KiB

1 week ago
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const store_modules_car = require("../../store/modules/car.js");
  5. const pages_index_comp_allCity = require("./comp/allCity.js");
  6. const config_site_config = require("../../config/site.config.js");
  7. const config_api = require("../../config/api.js");
  8. var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
  9. if (!Array) {
  10. const _easycom_up_navbar2 = common_vendor.resolveComponent("up-navbar");
  11. const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  12. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  13. const _easycom_oneBtn2 = common_vendor.resolveComponent("oneBtn");
  14. (_easycom_up_navbar2 + _easycom_up_icon2 + _easycom_u_icon2 + _easycom_oneBtn2)();
  15. }
  16. const _easycom_up_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
  17. const _easycom_up_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  18. const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  19. const _easycom_oneBtn = () => "../../components/oneBtn/oneBtn.js";
  20. if (!Math) {
  21. (_easycom_up_navbar + _easycom_up_icon + _easycom_u_icon + _easycom_oneBtn)();
  22. }
  23. const _sfc_main = {
  24. __name: "index",
  25. setup(__props) {
  26. let usecarStore = store_modules_car.carStore();
  27. let {
  28. mapKey
  29. } = config_site_config.obj;
  30. const rightClick = () => {
  31. console.log("rightClick");
  32. };
  33. const tabData = common_vendor.ref([
  34. { name: "小车", type: "C1/C2/C3", style: "width: 114rpx;height: 61rpx;", icon: new URL("@/static/images/car4.png", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("pages/index/index.js", document.baseURI).href).href, id: "1" },
  35. { name: "货车", type: "A2/B2", style: "width: 106rpx;height: 68rpx;", icon: new URL("@/static/images/car2.png", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("pages/index/index.js", document.baseURI).href).href, id: "1" },
  36. { name: "客车", type: "A1/B1/A3", style: "width: 106rpx;height: 68rpx;", icon: new URL("@/static/images/car1.png", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("pages/index/index.js", document.baseURI).href).href, id: "1" },
  37. { name: "摩托车", type: "D/E/F", style: "width: 102rpx;height: 73rpx;", icon: new URL("@/static/images/car3.png", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("pages/index/index.js", document.baseURI).href).href, id: "1" }
  38. ]);
  39. const currentCar = common_vendor.ref("");
  40. function chooseCar(item) {
  41. currentCar.value = item;
  42. usecarStore.setCar("carType", item.carType);
  43. usecarStore.setCar("carTypeName", item.title);
  44. }
  45. function oneBtnClick() {
  46. common_vendor.index.navigateTo({
  47. url: "/pages/exercises/theoryStudy/theoryStudy"
  48. });
  49. }
  50. common_vendor.onLoad(async (option) => {
  51. let phone = option.phone ? option.phone : "18267103167";
  52. let type = option.type ? option.type : "1";
  53. console.log("自私");
  54. await loginFn(phone, type);
  55. questbanktypeFn();
  56. });
  57. async function loginFn(phone, type) {
  58. console.log("会执行吗??");
  59. const res = await config_api.loginApi({
  60. "username": phone,
  61. type
  62. });
  63. console.log(res);
  64. res.data.phone = phone;
  65. res.data.type = type;
  66. common_vendor.index.setStorageSync("loginInfo", res.data);
  67. }
  68. async function questbanktypeFn() {
  69. const { data: res } = await config_api.questbanktypeApi();
  70. let arr = res.map((item) => {
  71. item.descriptionArr = item.description.split(":");
  72. return item;
  73. });
  74. tabData.value = arr;
  75. currentCar.value = res[0];
  76. }
  77. common_vendor.onPullDownRefresh(() => {
  78. questbanktypeFn().then(() => {
  79. common_vendor.index.stopPullDownRefresh();
  80. }).catch(() => {
  81. common_vendor.index.stopPullDownRefresh();
  82. });
  83. });
  84. let citys = [];
  85. function initcity() {
  86. let cityArr = pages_index_comp_allCity.allCity.map((arr) => {
  87. return arr.cityInfoList.map((item) => {
  88. let obj = {
  89. cityName: item.cityName,
  90. pinYin: item.cityPinyin,
  91. py: item.cityAcronym.toLocaleLowerCase(),
  92. code: item.cityCode,
  93. cityInitial: item.cityInitial
  94. };
  95. return obj;
  96. });
  97. });
  98. citys = cityArr.flat();
  99. console.log(citys);
  100. }
  101. initcity();
  102. function getWarpweft() {
  103. common_vendor.index.getLocation({
  104. type: "wgs84",
  105. success: function(res) {
  106. console.log("当前位置的经度:" + res.longitude);
  107. console.log("当前位置的纬度:" + res.latitude);
  108. let url = "https://apis.map.qq.com/ws/geocoder/v1/";
  109. common_vendor.o$1(url, {
  110. key: mapKey,
  111. location: res.latitude + "," + res.longitude,
  112. output: "jsonp"
  113. }).then((res2) => {
  114. console.log("jsonp", res2.result.address_component);
  115. let {
  116. province,
  117. city,
  118. district
  119. } = res2.result.address_component;
  120. console.log(province, city, district);
  121. let currentCity = citys.find((item) => item.cityName == city);
  122. if (!currentCity) {
  123. return common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  124. }
  125. usecarStore.setCar("city", currentCity.code);
  126. usecarStore.setCar("cityName", currentCity.cityName);
  127. console.log(currentCity, "当前城市");
  128. }).catch(() => {
  129. common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  130. });
  131. },
  132. fail() {
  133. common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  134. }
  135. });
  136. }
  137. return (_ctx, _cache) => {
  138. return common_vendor.e({
  139. a: common_vendor.o(rightClick),
  140. b: common_vendor.p({
  141. title: "选择类型",
  142. autoBack: true
  143. }),
  144. c: common_vendor.p({
  145. name: "map",
  146. size: "20"
  147. }),
  148. d: common_vendor.unref(usecarStore).carInfo.cityName
  149. }, common_vendor.unref(usecarStore).carInfo.cityName ? {
  150. e: common_vendor.t(common_vendor.unref(usecarStore).carInfo.cityName)
  151. } : {}, {
  152. f: common_vendor.o(getWarpweft),
  153. g: common_vendor.p({
  154. name: "arrow-right",
  155. color: "#1989FA",
  156. size: "14"
  157. }),
  158. h: common_vendor.o(($event) => _ctx.$goPage("/pages/index/comp/city")),
  159. i: common_vendor.f(tabData.value, (item, index, i0) => {
  160. return common_vendor.e({
  161. a: item.id == currentCar.value.id
  162. }, item.id == currentCar.value.id ? {
  163. b: common_assets._imports_0
  164. } : {}, {
  165. c: item.cover,
  166. d: common_vendor.t(item.title),
  167. e: common_vendor.f(item.descriptionArr, (item2, index2, i1) => {
  168. return {
  169. a: common_vendor.t(item2),
  170. b: index2
  171. };
  172. }),
  173. f: index,
  174. g: common_vendor.o(($event) => chooseCar(item), index),
  175. h: item.id == currentCar.value.id ? 1 : ""
  176. });
  177. }),
  178. j: common_vendor.o(oneBtnClick),
  179. k: common_vendor.p({
  180. text: "确 定"
  181. })
  182. });
  183. };
  184. }
  185. };
  186. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
  187. wx.createPage(MiniProgramPage);