Commit 14290eba by liimin

style(api): 统一代码格式和修复严格相等判断

- 统一导入路径引号使用双引号并移除多余空格
- 将松散相等(==)改为严格相等(===)和严格不等(!==)判断
- 修复 qs.uts 中 null 和 undefined 的严格判断
- 移除登录页面未使用的类型定义和冗余日志
- 调整 system-api.uts 的导入顺序和代码格式
1 parent 2f29f6dc
/**
* 精品/轻改 API(从 gl_tape/api/module/boutique.js 迁移)
*/
import http from '@/api/request/http.uts'
import http from "@/api/request/http.uts";
/** 轻改素材配置 */
export function getBoutiqueMaterialConfig(data: UTSJSONObject): Promise<any> {
return http.post({
'method': 'dj.api.boutique.recepiton.material.merchant.detail',
'projectName': 'boutique',
"method": "dj.api.boutique.recepiton.material.merchant.detail",
"projectName": "boutique",
...data
} as UTSJSONObject)
} as UTSJSONObject);
}
/** 查询商户套餐推荐配置列表 */
export function getBoutiquePackageList(data: UTSJSONObject): Promise<any> {
return http.post({
'method': 'dj.api.smartcarlife.receptionMaterialRecommendPackageConfig.getByMerchantId',
'projectName': 'boutique',
"method": "dj.api.smartcarlife.receptionMaterialRecommendPackageConfig.getByMerchantId",
"projectName": "boutique",
...data
} as UTSJSONObject)
} as UTSJSONObject);
}
......@@ -5,32 +5,32 @@ import http from "@/api/request/http.uts";
/** 获取交付人员列表 */
export function getEmployeeList(data: UTSJSONObject): Promise<any> {
return http.post({
'method': 'dj.api.smartcarlife.employee.getByMerchantId',
'projectName': 'boutique',
'sceneList': [0],
...data
} as UTSJSONObject)
return http.post({
"method": "dj.api.smartcarlife.employee.getByMerchantId",
"projectName": "boutique",
"sceneList": [0],
...data
} as UTSJSONObject);
}
/** 获取门店主营车品牌 */
export function getMerchantCarBrandList(merchantIdList: Array<string | number>): Promise<any> {
return http.post({
method: 'merchants.api.open.merchant.info',
projectName: 'merchants',
merchantIdList: merchantIdList,
merchantInfoSwitch: {
brandFlag: true
}
} as UTSJSONObject, false, 'merchant')
export function getMerchantCarBrandList(merchantIdList: Array<number | string>): Promise<any> {
return http.post({
method: "merchants.api.open.merchant.info",
projectName: "merchants",
merchantIdList,
merchantInfoSwitch: {
brandFlag: true
}
} as UTSJSONObject, false, "merchant");
}
/**
* 车型
*/
export function getCarBrandsListApi(data: UTSJSONObject): Promise<any> {
return http.post({
method: 'scrm.api.carlife.common.getCarSeriesList',
...data
} as UTSJSONObject, false, 'scrm')
return http.post({
method: "scrm.api.carlife.common.getCarSeriesList",
...data
} as UTSJSONObject, false, "scrm");
}
import * as receiption from "./receiption.uts";
export {
receiption
}
export * as receiption from "./receiption.uts";
......@@ -46,16 +46,16 @@ function stringifyRecursive(
options: StringifyOptions
): string {
const prefix = options.prefix ?? "";
const encoder = options.encoder != null ? options.encoder! : (str: string): string => defaultEncoder(str);
const encoder = options.encoder !== null ? options.encoder : (str: string): string => defaultEncoder(str);
const filter = options.filter;
const sort = options.sort;
const strictNullHandling = options.strictNullHandling ?? false;
const skipNulls = options.skipNulls ?? false;
const encodeValuesOnly = options.encodeValuesOnly ?? false;
const generateArrayPrefix = options.generateArrayPrefix != null ? options.generateArrayPrefix! : (p: string, k: string): string => defaultGenerateArrayPrefix(p, k);
const generateArrayPrefix = options.generateArrayPrefix !== null ? options.generateArrayPrefix : (p: string, k: string): string => defaultGenerateArrayPrefix(p, k);
const allowDots = options.allowDots ?? false;
const formatter = options.formatter != null ? options.formatter! : (str: string): string => defaultFormatter(str);
const serializeDate = options.serializeDate != null ? options.serializeDate! : (date: Date): string => defaultSerializeDate(date);
const formatter = options.formatter !== null ? options.formatter : (str: string): string => defaultFormatter(str);
const serializeDate = options.serializeDate !== null ? options.serializeDate : (date: Date): string => defaultSerializeDate(date);
let processedObj: any | null = obj;
......@@ -83,7 +83,7 @@ function stringifyRecursive(
const values: string[] = [];
if (processedObj == null) {
if (processedObj === null) {
return "";
}
......@@ -98,7 +98,7 @@ function stringifyRecursive(
targetObj = new UTSJSONObject(processedObj);
}
} else {
if (processedObj != null) {
if (processedObj !== null) {
if (Array.isArray(processedObj)) {
const arr = processedObj as any[];
for (let i = 0; i < arr.length; i++) {
......@@ -117,7 +117,7 @@ function stringifyRecursive(
objKeys.push(key);
});
}
if (sort != null) {
if (sort !== null) {
objKeys = objKeys.sort(sort);
}
}
......@@ -128,7 +128,7 @@ function stringifyRecursive(
if (Array.isArray(targetObj)) {
const idx = Number.parseInt(key);
if (!isNaN(idx)) {
if (!Number.isNaN(idx)) {
value = (targetObj as any[])[idx];
}
} else {
......@@ -140,8 +140,8 @@ function stringifyRecursive(
}
const nextPrefix = Array.isArray(targetObj)
? (prefix != "" ? generateArrayPrefix(prefix, key) : key)
: (prefix != "" ? prefix + (allowDots ? `.${key}` : `[${key}]`) : key);
? (prefix !== "" ? generateArrayPrefix(prefix, key) : key)
: (prefix !== "" ? prefix + (allowDots ? `.${key}` : `[${key}]`) : key);
const newOptions: StringifyOptions = {
prefix: nextPrefix,
......@@ -158,7 +158,7 @@ function stringifyRecursive(
};
const result = stringifyRecursive(value, newOptions);
if (result != "") {
if (result !== "") {
values.push(result);
}
}
......
......@@ -42,7 +42,7 @@ export function sign(params: UTSJSONObject, secret: string, noSignAttr: string[]
// 4. 获取 key 列表并排序
const sortedKeys: string[] = [];
for (const key in realObj) {
if (key == "sign") {
if (key === "sign") {
continue;
}
sortedKeys.push(key);
......@@ -53,7 +53,7 @@ export function sign(params: UTSJSONObject, secret: string, noSignAttr: string[]
for (const key of sortedKeys) {
let obj: any | null = realObj[key];
if (obj == null) {
if (obj === null) {
obj = "";
} else if (typeof obj === "object") {
obj = JSON.stringify(obj);
......
......@@ -11,7 +11,7 @@
maxlength="11"
placeholder="请输入手机号"
type="tel" />
<view v-if="mobile != ''"
<view v-if="mobile !== ''"
class="icon"
@click="clearMobile">
<icon color="#000"
......@@ -27,7 +27,7 @@
maxlength="4"
placeholder="请输入验证码"
type="number" />
<view v-if="code != ''"
<view v-if="code !== ''"
class="icon"
@click="clearCode">
<icon color="#000"
......@@ -41,12 +41,12 @@
{{ count > 0 ? `重新发送(${count}s)` : '获取验证码' }}
</view>
</view>
<button class="btn"
@click="login">
登录
</button>
<view class="form-footer">
<view class="autoLogin">
<radio :checked="readingStatus"
......@@ -66,7 +66,7 @@
</view>
</view>
</view>
<view class="app-code flex">
APP编码:{{ deviceId }}
<view class="sprite-icon icon-clone"
......@@ -78,17 +78,17 @@
<!-- <view class="test-entry" @click="goToTest">
<text>测试入口</text>
</view>
<view class="demo-test" :style="{ paddingLeft: $resState.config.demo.paddingLeft }">
<text :style="{ fontSize: $resState.config.demo.titleFontSize }">Resolution Demo Text</text>
<image mode="widthFix"
:src="$getResImg($resState.config.demo.heroImageSrc)"
<image mode="widthFix"
:src="$getResImg($resState.config.demo.heroImageSrc)"
:style="{ width: $resState.config.demo.heroImageWidth }">
</image>
</view> -->
</Layout>
</template>
<script setup lang="uts">
import { ref, watch } from "vue";
......@@ -98,45 +98,37 @@ import { onLoad } from "@dcloudio/uni-app";
// 手机号正则
const phoneRex = /^1([3-9])\d{9}$/;
// 登录返回 data 的结构(这里只挑我们需要的字段)
type LoginResultData = {
loginUserInfoList: any[] | null
noSignInUuid: null | string
sessionId: null | string
}
const mobile = ref<string>("");
const code = ref<string>("");
const count = ref<number>(0);
const noSignIn = ref<boolean>(true);
const readingStatus = ref<boolean>(false);
const deviceId = ref<string>("");
// 简单登录节流,防止连续点击
let lastLoginAt = 0;
const LOGIN_INTERVAL_MS = 200;
// 先定义会被其他函数调用的函数:getAccountLoginList / jump / doLogin / login / countDown
const getAccountLoginList = (loginUserInfoList: any[]): void => {
const stepIndex = loginUserInfoList.length == 1 ? 1 : 0;
const stepIndex = loginUserInfoList.length === 1 ? 1 : 0;
uni.navigateTo({
url: `/pages/common/accountItems/index?stepIndex=${stepIndex}`
});
};
const jump = (data: any, remember: boolean): void => {
const loginData = data as UTSJSONObject;
const loginUserInfoList = loginData.loginUserInfoList as any[] | null;
const sessionIdVal = loginData.sessionId as null | string;
const noSignInUuidVal = loginData.noSignInUuid as null | string;
if (loginUserInfoList != null && loginUserInfoList.length > 0) {
if (sessionIdVal != null && sessionIdVal != "") {
if (loginUserInfoList !== null && loginUserInfoList.length > 0) {
if (sessionIdVal !== null && sessionIdVal !== "") {
storage.set("sessionId", sessionIdVal, 0);
}
if (noSignInUuidVal != null && noSignInUuidVal != "" && remember) {
if (noSignInUuidVal !== null && noSignInUuidVal !== "" && remember) {
storage.set("noSignInUuid", noSignInUuidVal, 0);
}
getAccountLoginList(loginUserInfoList);
......@@ -146,7 +138,7 @@ const jump = (data: any, remember: boolean): void => {
});
}
};
const doLogin = async (): Promise<void> => {
console.log("doLogin mobile:", mobile.value);
const m = mobile.value;
......@@ -155,19 +147,19 @@ const doLogin = async (): Promise<void> => {
const agreed = readingStatus.value;
console.log("agreed:", agreed, "type:", typeof agreed);
try {
if (m == "") {
if (m === "") {
throw new Error("请输入手机号");
}
if (!phoneRex.test(m)) {
throw new Error("请输入正确的手机号");
}
if (smsCode == "") {
if (smsCode === "") {
throw new Error("请输入验证码");
}
if (agreed != true) {
if (agreed !== true) {
throw new Error("请您阅读并同意《隐私协议》");
}
const params: UTSJSONObject = {
mobile: m,
code: smsCode
......@@ -175,7 +167,7 @@ const doLogin = async (): Promise<void> => {
if (remember) {
params.noSignIn = remember;
}
uni.showLoading({
title: "加载中",
mask: true
......@@ -184,11 +176,11 @@ const doLogin = async (): Promise<void> => {
const res = await apiSmsLogin(params);
console.log("res", res);
uni.hideLoading();
const resCode = res != null ? res.code : null;
const data = res != null ? (res.data as any | null) : null;
const message = res != null ? (res.message as null | string) : null;
if (`${resCode}` == "0" && data != null) {
const resCode = res !== null ? res.code : null;
const data = res !== null ? (res.data as any | null) : null;
const message = res !== null ? (res.message as null | string) : null;
if (`${resCode}` === "0" && data !== null) {
jump(data, remember);
} else {
uni.showModal({
......@@ -209,17 +201,17 @@ const doLogin = async (): Promise<void> => {
});
}
};
const login = (): void => {
const now = Date.now();
if (now - lastLoginAt < LOGIN_INTERVAL_MS) {
return;
}
lastLoginAt = now;
doLogin();
};
function countDown(initial: number): void {
if (initial > 0) {
count.value = initial;
......@@ -235,24 +227,24 @@ function countDown(initial: number): void {
}
}, 1000);
}
// 下面是其余业务函数
const autoLoginByMobile = (): void => {
const m = mobile.value;
const c = code.value;
if (c != "" && m != "" && c.length == 4 && phoneRex.test(m)) {
if (c !== "" && m !== "" && c.length === 4 && phoneRex.test(m)) {
login();
}
};
const clearMobile = (): void => {
mobile.value = "";
};
const clearCode = (): void => {
code.value = "";
};
const copyDeviceId = (): void => {
uni.setClipboardData({
data: deviceId.value,
......@@ -264,9 +256,9 @@ const copyDeviceId = (): void => {
}
});
};
const autoLogin = async (noSignInUuid: string): Promise<void> => {
if (noSignInUuid == "") return;
if (noSignInUuid === "") return;
uni.showLoading({
title: "加载中",
mask: true
......@@ -276,20 +268,20 @@ const autoLogin = async (noSignInUuid: string): Promise<void> => {
noSignInUuid
} as UTSJSONObject);
uni.hideLoading();
const data = res != null ? (res.data as any | null) : null;
if (data != null) {
const data = res !== null ? (res.data as any | null) : null;
if (data !== null) {
jump(data, true);
}
} catch {
uni.hideLoading();
}
};
const getSmsCode = async (): Promise<void> => {
const m = mobile.value;
const c = count.value;
try {
if (m == "") {
if (m === "") {
throw new Error("请输入手机号");
}
if (!phoneRex.test(m)) {
......@@ -298,19 +290,19 @@ const getSmsCode = async (): Promise<void> => {
if (c > 0) {
throw new Error("验证码发送过于频繁,请稍后再试");
}
uni.showLoading({
title: "加载中",
mask: true
});
const res = await apiGetSmsCode({
mobile: m
} as UTSJSONObject);
uni.hideLoading();
const codeVal = res != null ? (res.code as null | string) : null;
const message = res != null ? (res.message as null | string) : null;
if (codeVal == "0") {
const codeVal = res !== null ? (res.code as null | string) : null;
const message = res !== null ? (res.message as null | string) : null;
if (codeVal === "0") {
uni.showToast({
title: "验证码已发送",
icon: "none"
......@@ -328,45 +320,43 @@ const getSmsCode = async (): Promise<void> => {
});
}
};
const openPrivacy = (): void => {
const url = "https://img01.glsx.com.cn/weapp/resource/saas/app/privacy.html";
uni.navigateTo({
url: `/pages/common/webview?url=${url}`
});
};
onLoad((options: null | UTSJSONObject) => {
const optMobile = options != null ? (options.mobile as null | string) : null;
if (optMobile != null && optMobile != "") {
const optMobile = options !== null ? (options.mobile as null | string) : null;
if (optMobile !== null && optMobile !== "") {
mobile.value = optMobile;
}
const noSignInUuid = storage.get("noSignInUuid") as null | string;
if (noSignInUuid != null && noSignInUuid != "") {
if (noSignInUuid !== null && noSignInUuid !== "") {
autoLogin(noSignInUuid);
}
const info = uni.getDeviceInfo();
if (info != null && info.deviceId != null) {
if (info !== null && info.deviceId !== null) {
deviceId.value = info.deviceId;
}
});
watch(mobile, () => {
autoLoginByMobile();
});
watch(code, () => {
autoLoginByMobile();
});
function toggleReadingStatus(): void {
console.log("toggleReadingStatus before:", readingStatus.value);
readingStatus.value = !readingStatus.value;
console.log("toggleReadingStatus after:", readingStatus.value);
}
function toggleNoSignIn(): void {
noSignIn.value = !noSignIn.value;
}
......@@ -377,7 +367,7 @@ function goToTest(): void {
});
}
</script>
<style scoped lang="scss">
// 引入拆分后的样式文件
@import "./styles/common.scss";
......@@ -392,12 +382,11 @@ function goToTest(): void {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 5px;
z-index: 999;
text {
color: #fff;
font-size: 14px;
}
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!