Skip to content

Commit 5b5b651

Browse files
committed
Merge branch 'demo'
2 parents 83ec5cb + 4886582 commit 5b5b651

File tree

10 files changed

+47
-24
lines changed

10 files changed

+47
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dist
1919
*.njsproj
2020
*.sln
2121
*.sw?
22+
.hbuilderx
2223

2324
.stylelintcache
2425
# rollup-plugin-visualizer 生成的分析文件

.hbuilderx/launch.json

-16
This file was deleted.

README.app.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66

77
> tips: mac 可以安装多个版本的软件,
88
> ![multiple-version](./screenshots/multiple-version.png)
9+
10+
## arr.at(-1) 真机运行报错
11+
12+
![Alt text](image.png)
13+
14+
通过设置 `vite.config.ts` `build.target` 设置为 `es2015` 未能解决。
15+
16+
只好使用传统方法替换 `at()`

image.png

132 KB
Loading

shell/rename.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# 只有存在新的 app 文件时,才执行这些操作!!否则会误删!!
55
if test -d ./dist/build/app; then
6-
echo '存在新打包出来的app'
6+
echo '存在新打包出来的app - build'
77

88
cd ./dist/build/
99

@@ -15,3 +15,17 @@ if test -d ./dist/build/app; then
1515
# 2、把 app 命名为 unibest_app_build
1616
mv ./app ./unibest_app_build
1717
fi
18+
19+
if test -d ./dist/dev/app; then
20+
echo '存在新打包出来的app - dev'
21+
22+
cd ./dist/dev/
23+
24+
# 1、删除旧的 rename 后的文件夹
25+
if test -d './unibest_app_dev'; then
26+
rm -rf ./unibest_app_dev
27+
fi
28+
29+
# 2、把 app 命名为 unibest_app_build
30+
mv ./app ./unibest_app_dev
31+
fi

src/hooks/useNavbarWeixin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { onReady } from '@dcloudio/uni-app'
2-
import { getIsTabbar } from '@/utils/index'
2+
import { getIsTabbar, getArrElementByIdx } from '@/utils/index'
33

44
export default () => {
55
// 获取页面栈
@@ -15,7 +15,7 @@ export default () => {
1515
// 基于小程序的 Page 类型扩展 uni-app 的 Page
1616
type PageInstance = Page.PageInstance & WechatMiniprogram.Page.InstanceMethods<any>
1717
// 获取当前页面实例,数组最后一项
18-
const pageInstance = getCurrentPages().at(-1) as PageInstance
18+
const pageInstance = getArrElementByIdx(getCurrentPages(), -1) as PageInstance
1919

2020
// 页面渲染完毕,绑定动画效果
2121
onReady(() => {

src/pages/demo/route-interceptor/index.vue

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</view>
1818
<button v-if="!isLogined" @click="setUserInfo" class="mt-4" type="primary">登陆</button>
1919
<button v-else @click="clearUserInfo" class="mt-4" type="warn">登出</button>
20+
<button class="mt-8" @click="testAt">测试 Array.prototype.at</button>
2021
</view>
2122
</template>
2223

@@ -35,6 +36,9 @@ const setUserInfo = () => {
3536
const clearUserInfo = () => {
3637
userStore.clearUserInfo()
3738
}
39+
const testAt = () => {
40+
console.log('Array.prototype.at typeof: ', typeof Array.prototype.at)
41+
}
3842
</script>
3943

4044
<style lang="scss" scoped>

src/pages/demo/route-interceptor/login-page.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<script lang="ts" setup>
2020
import { useUserStore } from '@/store'
2121
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
22+
import { getArrElementByIdx } from '@/utils'
2223
2324
const userStore = useUserStore()
2425
const pages = getCurrentPages()
@@ -39,8 +40,9 @@ onLoad((opt) => {
3940
})
4041
onReady(() => {
4142
const pages = getCurrentPages()
42-
console.log('route-interception.vue onReady last page:', isLogined.value, pages.at(-1))
43-
const currRoute = (pages.at(-1) as any).$page
43+
const lastPage = getArrElementByIdx(pages, -1)
44+
console.log('route-interception.vue onReady last page:', isLogined.value, lastPage)
45+
const currRoute = (lastPage as any).$page
4446
console.log('route-interception.vue onReady currRoute:', currRoute)
4547
if (!isLogined.value) {
4648
// redirect时都需要 encodeURIComponent 一下,否则获取到的参数不对

src/utils/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export const getIsTabbar = () => {
99
return false
1010
}
1111
const pages = getCurrentPages()
12-
const currPath = pages.at(-1).route
12+
const lastPage = getArrElementByIdx(pages, -1)
13+
const currPath = lastPage.route
1314
return !!pagesJson.tabBar.list.find((e) => e.pagePath === currPath)
1415
}
1516

@@ -32,11 +33,13 @@ export const testI18n = () => {
3233
export const currRoute = () => {
3334
const pages = getCurrentPages()
3435
console.log('pages:', pages)
35-
const currRoute = (pages.at(-1) as any).$page
36+
37+
const lastPage = getArrElementByIdx(pages, -1)
38+
const currRoute = (lastPage as any).$page
3639
// console.log('lastPage.$page:', currRoute)
3740
// console.log('lastPage.$page.fullpath:', currRoute.fullPath)
3841
// console.log('lastPage.$page.options:', currRoute.options)
39-
// console.log('lastPage.options:', (pages.at(-1) as any).options)
42+
// console.log('lastPage.options:', (lastPage as any).options)
4043
// 经过多端测试,只有 fullPath 靠谱,其他都不靠谱
4144
const { fullPath } = currRoute as { fullPath: string }
4245
console.log(fullPath)
@@ -114,3 +117,9 @@ export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((p
114117
* 只得到 path 数组
115118
*/
116119
export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path)
120+
121+
export const getArrElementByIdx = (arr: any[], index: number) => {
122+
if (index < 0) return arr[arr.length + index]
123+
if (index >= arr.length) return undefined
124+
return arr[index]
125+
}

vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export default ({ command, mode }) => {
114114
port: Number.parseInt(env.VITE_APP_PORT, 10),
115115
},
116116
build: {
117+
target: 'es2015',
117118
minify: 'terser',
118119
terserOptions: {
119120
compress: {

0 commit comments

Comments
 (0)