Commit a2bed2e4 by cen

fix: 修复bug

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