Commit a2bed2e4 by cen

fix: 修复bug

1 parent 200f23df
/** /**
* 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启 * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
*/ */
var isIos var isIos
// #ifdef APP-PLUS // #ifdef APP-PLUS
isIos = (plus.os.name == "iOS") isIos = (plus.os.name == "iOS")
// #endif // #endif
// 判断推送权限是否开启 // 判断推送权限是否开启
function judgeIosPermissionPush() { function judgeIosPermissionPush() {
var result = false; var result = false;
var UIApplication = plus.ios.import("UIApplication"); var UIApplication = plus.ios.import("UIApplication");
var app = UIApplication.sharedApplication(); var app = UIApplication.sharedApplication();
var enabledTypes = 0; var enabledTypes = 0;
if (app.currentUserNotificationSettings) { if (app.currentUserNotificationSettings) {
var settings = app.currentUserNotificationSettings(); var settings = app.currentUserNotificationSettings();
enabledTypes = settings.plusGetAttribute("types"); enabledTypes = settings.plusGetAttribute("types");
console.log("enabledTypes1:" + enabledTypes); console.log("enabledTypes1:" + enabledTypes);
if (enabledTypes == 0) { if (enabledTypes == 0) {
console.log("推送权限没有开启"); console.log("推送权限没有开启");
} else { } else {
result = true; result = true;
console.log("已经开启推送功能!") console.log("已经开启推送功能!")
} }
plus.ios.deleteObject(settings); plus.ios.deleteObject(settings);
} else { } else {
enabledTypes = app.enabledRemoteNotificationTypes(); enabledTypes = app.enabledRemoteNotificationTypes();
if (enabledTypes == 0) { if (enabledTypes == 0) {
console.log("推送权限没有开启!"); console.log("推送权限没有开启!");
} else { } else {
result = true; result = true;
console.log("已经开启推送功能!") console.log("已经开启推送功能!")
} }
console.log("enabledTypes2:" + enabledTypes); console.log("enabledTypes2:" + enabledTypes);
} }
plus.ios.deleteObject(app); plus.ios.deleteObject(app);
plus.ios.deleteObject(UIApplication); plus.ios.deleteObject(UIApplication);
return result; return result;
} }
// 判断定位权限是否开启 // 判断定位权限是否开启
function judgeIosPermissionLocation() { function judgeIosPermissionLocation() {
var result = false; var result = false;
var cllocationManger = plus.ios.import("CLLocationManager"); var cllocationManger = plus.ios.import("CLLocationManager");
var status = cllocationManger.authorizationStatus(); var status = cllocationManger.authorizationStatus();
result = (status != 2) result = (status != 2)
console.log("定位权限开启:" + result); console.log("定位权限开启:" + result);
// 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation
/* var enable = cllocationManger.locationServicesEnabled(); /* var enable = cllocationManger.locationServicesEnabled();
var status = cllocationManger.authorizationStatus(); var status = cllocationManger.authorizationStatus();
console.log("enable:" + enable); console.log("enable:" + enable);
console.log("status:" + status); console.log("status:" + status);
if (enable && status != 2) { if (enable && status != 2) {
result = true; result = true;
console.log("手机定位服务已开启且已授予定位权限"); console.log("手机定位服务已开启且已授予定位权限");
} else { } else {
console.log("手机系统的定位没有打开或未给予定位权限"); console.log("手机系统的定位没有打开或未给予定位权限");
} */ } */
plus.ios.deleteObject(cllocationManger); plus.ios.deleteObject(cllocationManger);
return result; return result;
} }
// 判断麦克风权限是否开启 // 判断麦克风权限是否开启
function judgeIosPermissionRecord() { function judgeIosPermissionRecord() {
var result = false; var result = false;
var avaudiosession = plus.ios.import("AVAudioSession"); var avaudiosession = plus.ios.import("AVAudioSession");
var avaudio = avaudiosession.sharedInstance(); var avaudio = avaudiosession.sharedInstance();
var permissionStatus = avaudio.recordPermission(); var permissionStatus = avaudio.recordPermission();
console.log("permissionStatus:" + permissionStatus); console.log("permissionStatus:" + permissionStatus);
if (permissionStatus == 1684369017 || permissionStatus == 1970168948) { if (permissionStatus == 1684369017 || permissionStatus == 1970168948) {
console.log("麦克风权限没有开启"); console.log("麦克风权限没有开启");
} else { } else {
result = true; result = true;
console.log("麦克风权限已经开启"); console.log("麦克风权限已经开启");
} }
plus.ios.deleteObject(avaudiosession); plus.ios.deleteObject(avaudiosession);
return result; return result;
} }
// 判断相机权限是否开启 // 判断相机权限是否开启
function judgeIosPermissionCamera() { function judgeIosPermissionCamera() {
var result = false; var result = false;
var AVCaptureDevice = plus.ios.import("AVCaptureDevice"); var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide'); var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
console.log("authStatus:" + authStatus); console.log("authStatus:" + authStatus);
if (authStatus == 3) { if (authStatus == 3) {
result = true; result = true;
console.log("相机权限已经开启"); console.log("相机权限已经开启");
} else { } else {
console.log("相机权限没有开启"); console.log("相机权限没有开启");
} }
plus.ios.deleteObject(AVCaptureDevice); plus.ios.deleteObject(AVCaptureDevice);
return result; return result;
} }
// 判断相册权限是否开启 // 判断相册权限是否开启
function judgeIosPermissionPhotoLibrary() { function judgeIosPermissionPhotoLibrary() {
var result = false; var result = false;
var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary"); var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
var authStatus = PHPhotoLibrary.authorizationStatus(); var authStatus = PHPhotoLibrary.authorizationStatus();
console.log("authStatus:" + authStatus); console.log("authStatus:" + authStatus);
if (authStatus == 3) { if (authStatus == 3) {
result = true; result = true;
console.log("相册权限已经开启"); console.log("相册权限已经开启");
} else { } else {
console.log("相册权限没有开启"); console.log("相册权限没有开启");
} }
plus.ios.deleteObject(PHPhotoLibrary); plus.ios.deleteObject(PHPhotoLibrary);
return result; return result;
} }
// 判断通讯录权限是否开启 // 判断通讯录权限是否开启
function judgeIosPermissionContact() { function judgeIosPermissionContact() {
var result = false; var result = false;
var CNContactStore = plus.ios.import("CNContactStore"); var CNContactStore = plus.ios.import("CNContactStore");
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0); var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
if (cnAuthStatus == 3) { if (cnAuthStatus == 3) {
result = true; result = true;
console.log("通讯录权限已经开启"); console.log("通讯录权限已经开启");
} else { } else {
console.log("通讯录权限没有开启"); console.log("通讯录权限没有开启");
} }
plus.ios.deleteObject(CNContactStore); plus.ios.deleteObject(CNContactStore);
return result; return result;
} }
// 判断日历权限是否开启 // 判断日历权限是否开启
function judgeIosPermissionCalendar() { function judgeIosPermissionCalendar() {
var result = false; var result = false;
var EKEventStore = plus.ios.import("EKEventStore"); var EKEventStore = plus.ios.import("EKEventStore");
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0); var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
if (ekAuthStatus == 3) { if (ekAuthStatus == 3) {
result = true; result = true;
console.log("日历权限已经开启"); console.log("日历权限已经开启");
} else { } else {
console.log("日历权限没有开启"); console.log("日历权限没有开启");
} }
plus.ios.deleteObject(EKEventStore); plus.ios.deleteObject(EKEventStore);
return result; return result;
} }
// 判断备忘录权限是否开启 // 判断备忘录权限是否开启
function judgeIosPermissionMemo() { function judgeIosPermissionMemo() {
var result = false; var result = false;
var EKEventStore = plus.ios.import("EKEventStore"); var EKEventStore = plus.ios.import("EKEventStore");
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1); var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
if (ekAuthStatus == 3) { if (ekAuthStatus == 3) {
result = true; result = true;
console.log("备忘录权限已经开启"); console.log("备忘录权限已经开启");
} else { } else {
console.log("备忘录权限没有开启"); console.log("备忘录权限没有开启");
} }
plus.ios.deleteObject(EKEventStore); plus.ios.deleteObject(EKEventStore);
return result; return result;
} }
// Android权限查询 // Android权限查询
function requestAndroidPermission(permissionID) { function requestAndroidPermission(permissionID) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.android.requestPermissions( plus.android.requestPermissions(
[permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装 [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装
function(resultObj) { function(resultObj) {
var result = 0; var result = 0;
for (var i = 0; i < resultObj.granted.length; i++) { for (var i = 0; i < resultObj.granted.length; i++) {
var grantedPermission = resultObj.granted[i]; var grantedPermission = resultObj.granted[i];
uni.$logger.local.info('已获取的权限:' + grantedPermission); console.log('已获取的权限:' + grantedPermission);
result = 1 result = 1
} }
for (var i = 0; i < resultObj.deniedPresent.length; i++) { for (var i = 0; i < resultObj.deniedPresent.length; i++) {
var deniedPresentPermission = resultObj.deniedPresent[i]; var deniedPresentPermission = resultObj.deniedPresent[i];
uni.$logger.local.info('拒绝本次申请的权限:' + deniedPresentPermission); console.log('拒绝本次申请的权限:' + deniedPresentPermission);
result = 0 result = 0
} }
for (var i = 0; i < resultObj.deniedAlways.length; i++) { for (var i = 0; i < resultObj.deniedAlways.length; i++) {
var deniedAlwaysPermission = resultObj.deniedAlways[i]; var deniedAlwaysPermission = resultObj.deniedAlways[i];
uni.$logger.local.info('永久拒绝申请的权限:' + deniedAlwaysPermission); console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
result = -1 result = -1
} }
resolve(result); resolve(result);
// 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限 // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
// if (result != 1) { // if (result != 1) {
// gotoAppPermissionSetting() // gotoAppPermissionSetting()
// } // }
}, },
function(error) { function(error) {
uni.$logger.error('申请权限错误:' + error.code + " = " + error.message); console.log('申请权限错误:' + error.code + " = " + error.message);
resolve({ resolve({
code: error.code, code: error.code,
message: error.message message: error.message
}); });
} }
); );
}); });
} }
// 使用一个方法,根据参数判断权限 // 使用一个方法,根据参数判断权限
function judgeIosPermission(permissionID) { function judgeIosPermission(permissionID) {
if (permissionID == "location") { if (permissionID == "location") {
return judgeIosPermissionLocation() return judgeIosPermissionLocation()
} else if (permissionID == "camera") { } else if (permissionID == "camera") {
return judgeIosPermissionCamera() return judgeIosPermissionCamera()
} else if (permissionID == "photoLibrary") { } else if (permissionID == "photoLibrary") {
return judgeIosPermissionPhotoLibrary() return judgeIosPermissionPhotoLibrary()
} else if (permissionID == "record") { } else if (permissionID == "record") {
return judgeIosPermissionRecord() return judgeIosPermissionRecord()
} else if (permissionID == "push") { } else if (permissionID == "push") {
return judgeIosPermissionPush() return judgeIosPermissionPush()
} else if (permissionID == "contact") { } else if (permissionID == "contact") {
return judgeIosPermissionContact() return judgeIosPermissionContact()
} else if (permissionID == "calendar") { } else if (permissionID == "calendar") {
return judgeIosPermissionCalendar() return judgeIosPermissionCalendar()
} else if (permissionID == "memo") { } else if (permissionID == "memo") {
return judgeIosPermissionMemo() return judgeIosPermissionMemo()
} }
return false; return false;
} }
// 跳转到**应用**的权限页面 // 跳转到**应用**的权限页面
function gotoAppPermissionSetting() { function gotoAppPermissionSetting() {
if (isIos) { if (isIos) {
var UIApplication = plus.ios.import("UIApplication"); var UIApplication = plus.ios.import("UIApplication");
var application2 = UIApplication.sharedApplication(); var application2 = UIApplication.sharedApplication();
var NSURL2 = plus.ios.import("NSURL"); var NSURL2 = plus.ios.import("NSURL");
// var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES"); // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
var setting2 = NSURL2.URLWithString("app-settings:"); var setting2 = NSURL2.URLWithString("app-settings:");
application2.openURL(setting2); application2.openURL(setting2);
plus.ios.deleteObject(setting2); plus.ios.deleteObject(setting2);
plus.ios.deleteObject(NSURL2); plus.ios.deleteObject(NSURL2);
plus.ios.deleteObject(application2); plus.ios.deleteObject(application2);
} else { } else {
// console.log(plus.device.vendor); // console.log(plus.device.vendor);
var Intent = plus.android.importClass("android.content.Intent"); var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings"); var Settings = plus.android.importClass("android.provider.Settings");
var Uri = plus.android.importClass("android.net.Uri"); var Uri = plus.android.importClass("android.net.Uri");
var mainActivity = plus.android.runtimeMainActivity(); var mainActivity = plus.android.runtimeMainActivity();
var intent = new Intent(); var intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
intent.setData(uri); intent.setData(uri);
mainActivity.startActivity(intent); mainActivity.startActivity(intent);
} }
} }
// 检查系统的设备服务是否开启 // 检查系统的设备服务是否开启
// var checkSystemEnableLocation = async function () { // var checkSystemEnableLocation = async function () {
function checkSystemEnableLocation() { function checkSystemEnableLocation() {
if (isIos) { if (isIos) {
var result = false; var result = false;
var cllocationManger = plus.ios.import("CLLocationManager"); var cllocationManger = plus.ios.import("CLLocationManager");
var result = cllocationManger.locationServicesEnabled(); var result = cllocationManger.locationServicesEnabled();
console.log("系统定位开启:" + result); console.log("系统定位开启:" + result);
plus.ios.deleteObject(cllocationManger); plus.ios.deleteObject(cllocationManger);
return result; return result;
} else { } else {
var context = plus.android.importClass("android.content.Context"); var context = plus.android.importClass("android.content.Context");
var locationManager = plus.android.importClass("android.location.LocationManager"); var locationManager = plus.android.importClass("android.location.LocationManager");
var main = plus.android.runtimeMainActivity(); var main = plus.android.runtimeMainActivity();
var mainSvr = main.getSystemService(context.LOCATION_SERVICE); var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
console.log("系统定位开启:" + result); console.log("系统定位开启:" + result);
return result return result
} }
} }
module.exports = { module.exports = {
judgeIosPermission: judgeIosPermission, judgeIosPermission: judgeIosPermission,
requestAndroidPermission: requestAndroidPermission, requestAndroidPermission: requestAndroidPermission,
checkSystemEnableLocation: checkSystemEnableLocation, checkSystemEnableLocation: checkSystemEnableLocation,
gotoAppPermissionSetting: gotoAppPermissionSetting gotoAppPermissionSetting: gotoAppPermissionSetting
} }
...@@ -80,11 +80,35 @@ ...@@ -80,11 +80,35 @@
<!-- 弹窗 --> <!-- 弹窗 -->
<OrderPopup ref="orderPopup" :data="displayData" :isDefeatOrder="true" :externalData="[]" @onConfirm="onConfirm" :popupType="0" /> <OrderPopup ref="orderPopup" :data="displayData" :isDefeatOrder="true" :externalData="[]" @onConfirm="onConfirm" :popupType="0" />
<SelectCar ref="selectCar" title="选择车型" @car-selected="handleCarSelected" /> <SelectCar ref="selectCar" title="选择车型" @car-selected="handleCarSelected" />
<SelectCity ref="selectCity" title="选择城市" @city-selected="handleCitySelected" /> <SelectCity
<SelectCity ref="selectCarCity" title="选择城市" @city-selected="handleCarCitySelected" /> ref="selectCity"
title="选择城市"
@city-selected="handleCitySelected"
:defaultProvince="{
code: formData.carBaseReqDTO.registrationProvinceId,
name: formData.carBaseReqDTO.registrationProvinceName
}"
:defaultCity="{
code: formData.carBaseReqDTO.registrationCityId,
name: formData.carBaseReqDTO.registrationCityName
}"
/>
<SelectCity
ref="selectCarCity"
title="选择城市"
@city-selected="handleCarCitySelected"
:defaultProvince="{
code: formData.carBaseReqDTO.carProvinceId,
name: formData.carBaseReqDTO.carProvinceName
}"
:defaultCity="{
code: formData.carBaseReqDTO.carCityId,
name: formData.carBaseReqDTO.carCityName
}"
/>
<GeneralPopup ref="calendarGeneralPopup" popupClass="calendarGeneralPopup" :showClose="false" :showTitle="false" @confirm="confirmCalendar"> <GeneralPopup ref="calendarGeneralPopup" popupClass="calendarGeneralPopup" :showClose="false" :showTitle="false" @confirm="confirmCalendar">
<template #content> <template #content>
<uni-calendar class="calendar" :showMonth="false" :endDate="endDate" @change="calendarChange" /> <uni-calendar class="calendar" :showMonth="false" :startDate="startDate" :endDate="endDate" @change="calendarChange" />
</template> </template>
</GeneralPopup> </GeneralPopup>
<GeneralPopup ref="tipsPopup" popupClass="tipsPopup" type="center" :showClose="true" :showTitle="false" :noTitle="true"> <GeneralPopup ref="tipsPopup" popupClass="tipsPopup" type="center" :showClose="true" :showTitle="false" :noTitle="true">
...@@ -124,7 +148,7 @@ import UploadMedia from './components/uploadMedia.vue' ...@@ -124,7 +148,7 @@ import UploadMedia from './components/uploadMedia.vue'
import NoticePopup from '@/components/NoticePopup.vue' import NoticePopup from '@/components/NoticePopup.vue'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { max } from 'lodash' import permision from '@/js_sdk/wa-permission/permission.js'
export default { export default {
name: 'AddEvaluationFrom', name: 'AddEvaluationFrom',
components: { components: {
...@@ -159,6 +183,7 @@ export default { ...@@ -159,6 +183,7 @@ export default {
popupTypeEnum, popupTypeEnum,
title: '新增评估单', title: '新增评估单',
selectedCarInfo: null, selectedCarInfo: null,
startDate: '',
endDate: dayjs().format('YYYY-MM-DD'), endDate: dayjs().format('YYYY-MM-DD'),
isExistSamePlate: false, isExistSamePlate: false,
formData: { formData: {
...@@ -851,15 +876,15 @@ export default { ...@@ -851,15 +876,15 @@ export default {
this.$set(this.formData.carBaseReqDTO, 'carTypeName', date.year.name) this.$set(this.formData.carBaseReqDTO, 'carTypeName', date.year.name)
}, },
handleCitySelected(date) { handleCitySelected(date) {
this.$set(this.formData.carBaseReqDTO, 'registrationProvinceId', '') this.$set(this.formData.carBaseReqDTO, 'registrationProvinceId', date.province.code)
this.$set(this.formData.carBaseReqDTO, 'registrationProvinceName', date.province.name) this.$set(this.formData.carBaseReqDTO, 'registrationProvinceName', date.province.name)
this.$set(this.formData.carBaseReqDTO, 'registrationCityId', '') this.$set(this.formData.carBaseReqDTO, 'registrationCityId', date.city.code)
this.$set(this.formData.carBaseReqDTO, 'registrationCityName', date.city.name) this.$set(this.formData.carBaseReqDTO, 'registrationCityName', date.city.name)
}, },
handleCarCitySelected(date) { handleCarCitySelected(date) {
this.$set(this.formData.carBaseReqDTO, 'carProvinceId', '') this.$set(this.formData.carBaseReqDTO, 'carProvinceId', date.province.code)
this.$set(this.formData.carBaseReqDTO, 'carProvinceName', date.province.name) this.$set(this.formData.carBaseReqDTO, 'carProvinceName', date.province.name)
this.$set(this.formData.carBaseReqDTO, 'carCityId', '') this.$set(this.formData.carBaseReqDTO, 'carCityId', date.city.code)
this.$set(this.formData.carBaseReqDTO, 'carCityName', date.city.name) this.$set(this.formData.carBaseReqDTO, 'carCityName', date.city.name)
console.log('handleCarCitySelected', this.formData.carBaseReqDTO) console.log('handleCarCitySelected', this.formData.carBaseReqDTO)
}, },
...@@ -1031,7 +1056,22 @@ export default { ...@@ -1031,7 +1056,22 @@ export default {
}) })
}, },
scan(type) { async scan(type) {
const photoLibrary = await permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
const camera = await permision.requestAndroidPermission('android.permission.CAMERA')
const isOnline = await uni.$isNetWork()
if (photoLibrary != 1) {
uni.showToast({ title: '您的设备不支持相册功能或未授权访问,请前往设置中开启相册权限', icon: 'none' })
return
}
if (camera != 1) {
uni.showToast({ title: '您的设备不支持摄像头功能或未授权访问,请前往设置中开启摄像头权限', icon: 'none' })
return
}
if (!isOnline) {
uni.showToast({ title: '当前无网络连接,请连接网络后重试', icon: 'none' })
return
}
uni.showActionSheet({ uni.showActionSheet({
itemList: ['拍照', '从相册选择'], itemList: ['拍照', '从相册选择'],
success: res => { success: res => {
......
...@@ -149,6 +149,9 @@ export default { ...@@ -149,6 +149,9 @@ export default {
width: 100%; width: 100%;
height: toRpx(164); height: toRpx(164);
background-color: #fff; background-color: #fff;
.btn {
width: toRpx(720);
}
} }
} }
//小弹窗 //小弹窗
...@@ -221,7 +224,7 @@ export default { ...@@ -221,7 +224,7 @@ export default {
width: 100%; width: 100%;
} }
.btn { .btn {
flex: 1; width: toRpx(720);
height: toRpx(76); height: toRpx(76);
border-radius: toRpx(48); border-radius: toRpx(48);
opacity: 1; opacity: 1;
......
<template> <template>
<GeneralPopup ref="carPopup" popupClass="carPopup" :list="list" :title="title" @confirm="handleConfirm"> <GeneralPopup ref="cityPopup" popupClass="cityPopup" :list="list" :title="title" @confirm="handleConfirm">
<template v-slot:content> <template v-slot:content>
<StepTab :steps="steps" :currentStep="currentStep" :clickable="true" @step-change="onStepChange" :isShowStepNumber="false"></StepTab> <view v-if="isLoading" class="loading-container">
<view class="list-component"> <view class="loading-spinner"></view>
<SortByNameList :items="currentStepData" :activeValue="currentSelectedId" :activeField="'name'" :itemNameField="'name'" :groupKeyField="'letter'" :itemsPerRow="3" :itemSpacing="32" @item-click="handleItemClick" /> <text class="loading-text">加载中...</text>
</view>
<view v-else class="content-container">
<StepTab :steps="dynamicSteps" :currentStep="currentStep" :clickable="true" @step-change="onStepChange" :isShowStepNumber="false"></StepTab>
<view class="list-component">
<SortByNameList :items="currentStepData" :activeValue="currentSelectedId" :activeField="'code'" :itemNameField="'name'" :groupKeyField="'letter'" :itemsPerRow="3" :itemSpacing="32" @item-click="handleItemClick" />
</view>
</view> </view>
</template> </template>
</GeneralPopup> </GeneralPopup>
...@@ -15,7 +21,7 @@ import StepTab from './StepTab.vue' ...@@ -15,7 +21,7 @@ import StepTab from './StepTab.vue'
import { sign, md532, md516 } from 'utils/common' import { sign, md532, md516 } from 'utils/common'
import pinyin from 'pinyin.js' import pinyin from 'pinyin.js'
export default { export default {
name: 'SelectCar', name: 'SelectCity',
components: { components: {
GeneralPopup, GeneralPopup,
SortByNameList, SortByNameList,
...@@ -24,11 +30,19 @@ export default { ...@@ -24,11 +30,19 @@ export default {
props: { props: {
title: { title: {
type: String, type: String,
default: '选择车型' default: '选择城市'
}, },
list: { list: {
type: Array, type: Array,
default: () => [] default: () => []
},
defaultProvince: {
type: Object,
default: null
},
defaultCity: {
type: Object,
default: null
} }
}, },
data() { data() {
...@@ -39,46 +53,55 @@ export default { ...@@ -39,46 +53,55 @@ export default {
{ label: '选择省份', number: 1 }, { label: '选择省份', number: 1 },
{ label: '选择市', number: 2 } { label: '选择市', number: 2 }
], ],
carBrandData: [], provinceData: [],
selectedBrand: null, selectedProvince: null,
selectedSeries: null, selectedCity: null,
selectedModel: null, selectionResult: null,
selectedYear: null, isLoading: true
loadingYearData: false, // 添加加载状态标记
selectionResult: null
} }
}, },
created() {
this.loadCityData()
},
computed: { computed: {
dynamicSteps() {
const newSteps = [...this.steps]
if (this.selectedProvince && this.selectedProvince.name) {
newSteps[0].label = this.selectedProvince.name
} else {
newSteps[0].label = '选择省份'
}
if (this.currentStep >= 1) {
if (this.selectedCity && this.selectedCity.name) {
newSteps[1].label = this.selectedCity.name
} else {
newSteps[1].label = '选择市'
}
}
return newSteps
},
currentStepData() { currentStepData() {
let data = [] let data = []
switch (this.currentStep) { switch (this.currentStep) {
case 0: case 0:
data = this.carBrandData.map(item => this.addLetterToItem(item)) data = this.provinceData.map(item => this.addLetterToItem(item))
break break
case 1: case 1:
data = (this.selectedBrand?.districts || []).map(item => this.addLetterToItem(item)) data = (this.selectedProvince?.districts || []).map(item => this.addLetterToItem(item))
break break
// case 2:
// data = (this.selectedSeries?.districts || []).map(item => this.addLetterToItem(item))
// break
// case 3:
// data = (this.selectedModel?.districts || []).map(item => this.addLetterToItem(item))
// break
default: default:
data = [] data = []
} }
console.log(`Step ${this.currentStep} data:`, data.length, 'items') console.log(`Step ${this.currentStep} data:`, data.length, 'items')
return data return data
} }
}, },
methods: { methods: {
loadCarData() { loadCityData() {
let that = this let that = this
this.isLoading = true
uni.request({ uni.request({
url: 'http://eshield.test.glsx.com.cn/nesi/apiRegion/search?keyword=全国&sub_admin=3&extensions_code=0', url: 'http://eshield.test.glsx.com.cn/nesi/apiRegion/search?keyword=全国&sub_admin=3&extensions_code=1',
method: 'GET', method: 'GET',
data: {}, data: {},
dataType: 'json', dataType: 'json',
...@@ -86,133 +109,109 @@ export default { ...@@ -86,133 +109,109 @@ export default {
console.log('请求结果:', JSON.parse(result.data.data)) console.log('请求结果:', JSON.parse(result.data.data))
let { status, districts } = JSON.parse(result.data.data) let { status, districts } = JSON.parse(result.data.data)
if (status === 0 && districts) { if (status === 0 && districts) {
that.carBrandData = districts[0].districts that.provinceData = districts[0].districts
console.log('carBrandData', that.carBrandData) console.log('provinceData', that.provinceData)
that.updateSelectionWithLoadedData()
} else { } else {
console.error('Invalid car data format:', result) console.error('Invalid city data format:', result)
} }
that.isLoading = false
}, },
fail(error) { fail(error) {
console.log(error, 'error') console.log(error, 'error')
that.isLoading = false
} }
}) })
}, },
updateSelectionWithLoadedData() {
// 加载指定车型的年份数据 console.log('Updating selection with loaded data...', this.defaultProvince)
loadYearDataForModel(model) { console.log('Updating selection with loaded data...', this.defaultCity)
console.log('loadYearDataForModel', model) console.log('Updating selection with loaded data...', this.provinceData)
// 如果已经加载过数据,则不再重复加载 if (this.defaultProvince && (this.defaultProvince.code || this.defaultProvince.id)) {
if (model.districts && model.districts.length > 0) { const defaultProvinceCode = String(this.defaultProvince.code || this.defaultProvince.id)
return Promise.resolve(model.districts) const foundProvince = this.provinceData.find(p => String(p.code) === defaultProvinceCode || String(p.id) === defaultProvinceCode)
} console.log('foundProvince', foundProvince)
if (foundProvince) {
this.loadingYearData = true this.selectedProvince = foundProvince
let that = this const defaultCityCode = this.defaultCity ? String(this.defaultCity.code || this.defaultCity.id) : null
const params = { if (defaultCityCode) {
app_key: '48e5e13229b82c1b4e6e8c96151f0637', const foundCity = foundProvince.districts?.find(c => String(c.code) === defaultCityCode || String(c.id) === defaultCityCode)
v: '1.0.0', if (foundCity) {
timestamp: '1234567890', this.selectedCity = foundCity
source: 'dev_author', this.currentStep = 1
method: 'glsx.accounts.base.car.types', this.currentSelectedId = foundCity.code
format: 'json',
csId: model.id
}
const secret = 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b'
const signature = sign(params, secret)
console.log('签名结果:', signature)
return new Promise((resolve, reject) => {
uni.request({
url: 'http://qcdidicb.glsx.com.cn/router?method=glsx.accounts.base.car.types',
method: 'GET',
dataType: 'json',
success(result) {
console.log('请求结果:', result)
if (result.data && result.data.code === '0' && result.data.data && result.data.data.carinfos) {
model.districts = result.data.data.carinfos
this.loadingYearData = false
resolve(model.districts)
} else {
reject(new Error('Invalid car data format'))
} }
},
fail(error) {
console.log(error, 'error')
} }
}) this.selectionResult = {
}) province: this.selectedProvince,
city: this.selectedCity
}
}
}
}, },
open() { open() {
console.log('Opening car selector popup') if (!this.defaultProvince) {
this.$refs.carPopup.open() this.resetSelection()
this.loadCarData() }
this.$nextTick(() => {
if (this.$refs.cityPopup) {
this.$refs.cityPopup.open()
}
})
},
resetSelection() {
this.currentStep = 0
this.currentSelectedId = null
this.selectedProvince = null
this.selectedCity = null
this.selectionResult = null
}, },
onStepChange(index) { onStepChange(index) {
console.log(`Changing step from ${this.currentStep} to ${index}`) console.log(`Changing step from ${this.currentStep} to ${index}`)
// 限制只能前进到已选择的下一级
if (index === 0) { if (index === 0) {
this.currentStep = 0 this.currentStep = 0
} else if (index === 1 && this.selectedBrand) { this.currentSelectedId = this.selectedProvince?.code || null
} else if (index === 1 && this.selectedProvince) {
this.currentStep = 1 this.currentStep = 1
this.currentSelectedId = this.selectedCity?.code || null
} }
// 重置当前步骤的选中ID
this.currentSelectedId = null
}, },
// 处理项目点击事件
handleItemClick(item) { handleItemClick(item) {
console.log('Item clicked:', item) this.currentSelectedId = item.code
this.currentSelectedId = item.id || item.name
if (this.currentStep === 0) { if (this.currentStep === 0) {
this.selectedBrand = item this.selectedProvince = item
this.selectedSeries = null this.selectedCity = null
this.selectedModel = null
this.selectedYear = null
this.currentStep = 1 this.currentStep = 1
this.$emit('brand-selected', item) this.$emit('province-selected', item)
} else if (this.currentStep === 1) { } else if (this.currentStep === 1) {
this.selectedSeries = item this.selectedCity = item
this.selectedModel = null this.$emit('city-selected', item)
this.selectedYear = null
this.$emit('series-selected', item)
} }
this.selectionResult = { this.selectionResult = {
province: this.selectedBrand, province: this.selectedProvince,
city: this.selectedSeries city: this.selectedCity
} }
}, },
// 为数据项添加首字母
addLetterToItem(item) { addLetterToItem(item) {
if (!item || !item.name) { if (!item || !item.name) {
return { ...item, letter: '#' } return { ...item, letter: '#' }
} }
try { try {
const firstChar = item.name.charAt(0) const firstChar = item.name.charAt(0)
if (/[一-龥]/.test(firstChar)) {
if (/[\u4e00-\u9fa5]/.test(firstChar)) {
let pinyinResult let pinyinResult
try { try {
pinyinResult = pinyin(firstChar) pinyinResult = pinyin(firstChar)
} catch (e1) { } catch (e1) {
console.warn('pinyin without options failed:', e1) console.warn('pinyin without options failed:', e1)
try { try {
pinyinResult = pinyin(firstChar, { style: 0 }) pinyinResult = pinyin(firstChar, { style: 0 })
} catch (e2) { } catch (e2) {
console.warn('pinyin with simple options failed:', e2) console.warn('pinyin with simple options failed:', e2)
const simplePinyinMap = { const simplePinyinMap = {
安: 'A', 安: 'A',
北: 'B', 北: 'B',
重: 'C', 重: 'C',
重: 'C',
川: 'C', 川: 'C',
大: 'D', 大: 'D',
东: 'D', 东: 'D',
...@@ -241,14 +240,12 @@ export default { ...@@ -241,14 +240,12 @@ export default {
云: 'Y', 云: 'Y',
浙: 'Z' 浙: 'Z'
} }
return { return {
...item, ...item,
letter: simplePinyinMap[firstChar] || '#' letter: simplePinyinMap[firstChar] || '#'
} }
} }
} }
let letter = '#' let letter = '#'
if (pinyinResult && pinyinResult.length > 0) { if (pinyinResult && pinyinResult.length > 0) {
if (Array.isArray(pinyinResult[0])) { if (Array.isArray(pinyinResult[0])) {
...@@ -259,7 +256,6 @@ export default { ...@@ -259,7 +256,6 @@ export default {
letter = pinyinResult.charAt(0).toUpperCase() letter = pinyinResult.charAt(0).toUpperCase()
} }
} }
if (/^[A-Z]$/.test(letter)) { if (/^[A-Z]$/.test(letter)) {
return { ...item, letter } return { ...item, letter }
} else { } else {
...@@ -281,7 +277,6 @@ export default { ...@@ -281,7 +277,6 @@ export default {
return { ...item, letter: '#' } return { ...item, letter: '#' }
} }
}, },
handleConfirm() { handleConfirm() {
console.log(this.selectionResult) console.log(this.selectionResult)
this.$emit('city-selected', this.selectionResult) this.$emit('city-selected', this.selectionResult)
...@@ -290,7 +285,7 @@ export default { ...@@ -290,7 +285,7 @@ export default {
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
::v-deep .carPopup { ::v-deep .cityPopup {
.content { .content {
width: 100%; width: 100%;
height: toRpx(764); height: toRpx(764);
...@@ -300,7 +295,42 @@ export default { ...@@ -300,7 +295,42 @@ export default {
.list-component { .list-component {
width: 100%; width: 100%;
height: calc(100% - #{toRpx(100)}); height: calc(100% - #{toRpx(100)});
overflow-y: auto;
} }
} }
} }
.content-container {
width: 100%;
height: 100%
}
.loading-container {
width: 100%;
height: toRpx(764);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #fff;
}
.loading-spinner {
width: toRpx(60);
height: toRpx(60);
border: toRpx(6) solid #f3f3f3;
border-top: toRpx(6) solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
.loading-text {
margin-top: toRpx(20);
color: #666;
font-size: toRpx(28);
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style> </style>
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
<script> <script>
// import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js' // import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { uploadFile } from '@/utils/ossUpload.js' import { uploadFile } from '@/utils/ossUpload.js'
import permision from '@/js_sdk/wa-permission/permission.js'
export default { export default {
name: 'UploadMedia', name: 'UploadMedia',
...@@ -73,7 +74,22 @@ export default { ...@@ -73,7 +74,22 @@ export default {
}, },
methods: { methods: {
// 处理媒体上传 // 处理媒体上传
handleMediaUpload(field) { async handleMediaUpload(field) {
const photoLibrary = await permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
const camera = await permision.requestAndroidPermission('android.permission.CAMERA')
const isOnline = await uni.$isNetWork()
if (photoLibrary != 1) {
uni.showToast({ title: '您的设备不支持相册功能或未授权访问,请前往设置中开启相册权限', icon: 'none' })
return
}
if (camera != 1) {
uni.showToast({ title: '您的设备不支持摄像头功能或未授权访问,请前往设置中开启摄像头权限', icon: 'none' })
return
}
if (!isOnline) {
uni.showToast({ title: '当前无网络连接,请连接网络后重试', icon: 'none' })
return
}
// 根据字段类型显示不同的操作菜单 // 根据字段类型显示不同的操作菜单
const itemList = [] const itemList = []
if (field.accept === 'image' || !field.accept) { if (field.accept === 'image' || !field.accept) {
......
...@@ -114,6 +114,7 @@ import OrderPopup from '@/components/OrderPopup/index.vue' ...@@ -114,6 +114,7 @@ import OrderPopup from '@/components/OrderPopup/index.vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import NoticePopup from '@/components/NoticePopup.vue' import NoticePopup from '@/components/NoticePopup.vue'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import permision from '@/js_sdk/wa-permission/permission.js'
export default { export default {
components: { components: {
FormCell, FormCell,
...@@ -374,7 +375,22 @@ export default { ...@@ -374,7 +375,22 @@ export default {
}) })
} }
}, },
handleImageUpload(field) { async handleImageUpload(field) {
const photoLibrary = await permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
const camera = await permision.requestAndroidPermission('android.permission.CAMERA')
const isOnline = await uni.$isNetWork()
if (photoLibrary != 1) {
uni.showToast({ title: '您的设备不支持相册功能或未授权访问,请前往设置中开启相册权限', icon: 'none' })
return
}
if (camera != 1) {
uni.showToast({ title: '您的设备不支持摄像头功能或未授权访问,请前往设置中开启摄像头权限', icon: 'none' })
return
}
if (!isOnline) {
uni.showToast({ title: '当前无网络连接,请连接网络后重试', icon: 'none' })
return
}
// 显示操作菜单,让用户选择拍照或从相册选择 // 显示操作菜单,让用户选择拍照或从相册选择
uni.showActionSheet({ uni.showActionSheet({
itemList: ['拍照', '从相册选择'], itemList: ['拍照', '从相册选择'],
......
...@@ -271,6 +271,7 @@ import dayjs from 'dayjs' ...@@ -271,6 +271,7 @@ import dayjs from 'dayjs'
import NoticePopup from '@/components/NoticePopup.vue' import NoticePopup from '@/components/NoticePopup.vue'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { max } from 'lodash' import { max } from 'lodash'
import permision from '@/js_sdk/wa-permission/permission.js'
export default { export default {
components: { components: {
FormCell, FormCell,
...@@ -823,7 +824,22 @@ export default { ...@@ -823,7 +824,22 @@ export default {
.join(', ') .join(', ')
console.log('selectedItemsText', this.selectedItemsText) console.log('selectedItemsText', this.selectedItemsText)
}, },
handleImageUpload(field) { async handleImageUpload(field) {
const photoLibrary = await permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
const camera = await permision.requestAndroidPermission('android.permission.CAMERA')
const isOnline = await uni.$isNetWork()
if (photoLibrary != 1) {
uni.showToast({ title: '您的设备不支持相册功能或未授权访问,请前往设置中开启相册权限', icon: 'none' })
return
}
if (camera != 1) {
uni.showToast({ title: '您的设备不支持摄像头功能或未授权访问,请前往设置中开启摄像头权限', icon: 'none' })
return
}
if (!isOnline) {
uni.showToast({ title: '当前无网络连接,请连接网络后重试', icon: 'none' })
return
}
uni.showActionSheet({ uni.showActionSheet({
itemList: ['拍照', '从相册选择'], itemList: ['拍照', '从相册选择'],
success: res => { success: res => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!