37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
import codecs
|
|
import re
|
|
|
|
path = r'd:\骅锋\mall\pages\user\login.uvue'
|
|
with codecs.open(path, 'r', 'utf-8') as f:
|
|
text = f.read()
|
|
|
|
# Define the old block using regex to handle variable whitespace/tabs
|
|
old_pattern = r"const merchantId = await checkMerchantAccess\(sessionUid,\s*account\.value\)\s*if\s*\(merchantId == null\)\s*\{\s*await supa\.signOut\(\)\s*logout\(\)\s*throw new Error\('您还没有注册商家端账户,快去注册一个'\)\s*\}\s*// 存入商家ID\s*uni\.setStorageSync\('merchant_id', merchantId\)"
|
|
|
|
new_code = '''const accessData = await checkAdminOrMerchantAccess(sessionUid, account.value)
|
|
if (accessData == null) {
|
|
await supa.signOut()
|
|
logout()
|
|
throw new Error('该账户无后台或商家端权限')
|
|
}
|
|
|
|
const currRole = accessData.getString('role')
|
|
const currId = accessData.getString('id')
|
|
uni.setStorageSync('adminRole', currRole)
|
|
|
|
if (currRole === 'merchant') {
|
|
uni.setStorageSync('merchant_id', currId)
|
|
} else {
|
|
uni.removeStorageSync('merchant_id')
|
|
}'''
|
|
|
|
# Replace it
|
|
if 'checkMerchantAccess' in text:
|
|
new_text = re.sub(old_pattern, new_code, text)
|
|
with codecs.open(path, 'w', 'utf-8') as f:
|
|
f.write(new_text)
|
|
print("Fixed checkMerchantAccess reference.")
|
|
else:
|
|
print("Not found.")
|
|
|