Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
V
vue3-quasar-ts-study01
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hucy
vue3-quasar-ts-study01
Commits
5b4aac46
Commit
5b4aac46
authored
Nov 07, 2022
by
hucy
☘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise学习
parent
2f37a34b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
305 additions
and
53 deletions
+305
-53
IndexPage.vue
src/modules/page6/IndexPage.vue
+2
-2
config.ts
src/modules/page6/config.ts
+127
-2
AsyncAwait.vue
src/modules/page6/element/AsyncAwait.vue
+66
-9
EquipmentPage.vue
src/modules/page6/element/equipment/EquipmentPage.vue
+81
-34
IndexPage.vue
src/modules/page6/element/equipment/IndexPage.vue
+29
-6
No files found.
src/modules/page6/IndexPage.vue
View file @
5b4aac46
...
@@ -15,8 +15,8 @@ export default {
...
@@ -15,8 +15,8 @@ export default {
// import CanvasStudy from './element/CanvasStudyCopy1.vue';
// import CanvasStudy from './element/CanvasStudyCopy1.vue';
// import CanvasStudy from './element/CanvasCurve.vue';
// import CanvasStudy from './element/CanvasCurve.vue';
//
import SubComponents from './element/AsyncAwait.vue';
import
SubComponents
from
'./element/AsyncAwait.vue'
;
import
SubComponents
from
'./element/equipment/IndexPage.vue'
;
//
import SubComponents from './element/equipment/IndexPage.vue';
</
script
>
</
script
>
<
template
>
<
template
>
<div
class=
"page6 container-height"
>
<div
class=
"page6 container-height"
>
...
...
src/modules/page6/config.ts
View file @
5b4aac46
...
@@ -526,12 +526,12 @@ export const machineList1 = [
...
@@ -526,12 +526,12 @@ export const machineList1 = [
{
{
code
:
'Z02'
,
code
:
'Z02'
,
state
:
'run'
,
state
:
'run'
,
color
:
'
red
'
,
color
:
'
pink
'
,
},
},
{
{
code
:
'Z03'
,
code
:
'Z03'
,
state
:
'run'
,
state
:
'run'
,
color
:
'
red
'
,
color
:
'
green
'
,
},
},
{
{
code
:
'Z04'
,
code
:
'Z04'
,
...
@@ -573,4 +573,129 @@ export const machineList1 = [
...
@@ -573,4 +573,129 @@ export const machineList1 = [
state
:
'run'
,
state
:
'run'
,
color
:
'red'
,
color
:
'red'
,
},
},
{
code
:
'Z012'
,
state
:
'run'
,
color
:
'red'
,
},
{
code
:
'Z013'
,
state
:
'run'
,
color
:
'red'
,
},
];
// 机台列表测试数据2
export
const
machineList2
=
[
{
code
:
'B01'
,
state
:
'run'
,
color
:
'pink'
,
},
{
code
:
'B02'
,
state
:
'run'
,
color
:
'pink'
,
},
{
code
:
'B03'
,
state
:
'run'
,
color
:
'pink'
,
},
{
code
:
'B04'
,
state
:
'run'
,
color
:
'pink'
,
},
{
code
:
'B05'
,
state
:
'run'
,
color
:
'pink'
,
},
// {
// code: 'B06',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B07',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B08',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B09',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B010',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B011',
// state: 'run',
// color: 'pink',
// },
// // 分割
// {
// code: 'B012',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B013',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B014',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B015',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B016',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B017',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B018',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B019',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B020',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B021',
// state: 'run',
// color: 'pink',
// },
// {
// code: 'B022',
// state: 'run',
// color: 'pink',
// },
];
];
src/modules/page6/element/AsyncAwait.vue
View file @
5b4aac46
<!-- eslint-disable @typescript-eslint/no-unused-vars -->
<!--
<!--
* async await return
* async await return
-->
-->
...
@@ -9,12 +10,12 @@ const msg = ref('');
...
@@ -9,12 +10,12 @@ const msg = ref('');
const
requestMsg
=
ref
(
''
);
const
requestMsg
=
ref
(
''
);
onMounted
(()
=>
{
onMounted
(()
=>
{
fun
();
fun
1
();
});
});
function
getMag
(
name
:
any
)
{
function
getMag
(
name
:
any
)
{
return
`Hello, my name is
${
name
}
.`
;
return
`Hello, my name is
${
name
}
.`
;
}
}
function
fun
()
{
function
fun
1
()
{
const
name
=
'张三'
;
const
name
=
'张三'
;
const
msg
=
getMag
(
name
);
const
msg
=
getMag
(
name
);
console
.
log
(
msg
);
// Hello, my name is 张三.
console
.
log
(
msg
);
// Hello, my name is 张三.
...
@@ -61,22 +62,64 @@ function heavyLoad() {
...
@@ -61,22 +62,64 @@ function heavyLoad() {
}
}
function
fetchApi
()
{
function
fetchApi
()
{
const
fetchPromise
=
fetch
(
fn
().
then
(
'https://mdn.github.io/learning-area/javascript/apis/fetching-data/can-store/products.json'
function
(
data
)
{
console
.
log
(
'resolve回调'
,
data
);
// console.log(somedata); // somedata未定义
},
function
(
error
)
{
console
.
log
(
'reject回调'
,
error
);
}
);
);
}
console
.
log
(
fetchPromise
);
function
fn
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fetchPromise
.
then
((
response
)
=>
{
setTimeout
(()
=>
{
console
.
log
(
`已收到响应:
${
response
.
status
}
`
);
// Math.random 生成0~1的随机数
// Math.ceil 向上取整
let
num
=
Math
.
ceil
(
Math
.
random
()
*
10
);
// 生成1~10的随机整数
if
(
num
<=
5
)
{
resolve
(
`执行成功,num的值为:
${
num
}
`
);
}
else
{
reject
(
`执行失败,该数字大于5,num的值为
${
num
}
`
);
}
},
1000
);
});
});
}
console
.
log
(
'已发送请求……'
);
async
function
fetchProducts
()
{
try
{
// 在这一行之后,我们的函数将等待 `fetch()` 调用完成
// 调用 `fetch()` 将返回一个“响应”或抛出一个错误
const
response
=
await
fetch
(
'https://mdn.github.io/learning-area/javascript/apis/fetching-data/can-store/products.json'
);
if
(
!
response
.
ok
)
{
throw
new
Error
(
`HTTP 请求错误:
${
response
.
status
}
`
);
}
else
{
console
.
log
(
response
);
}
// 在这一行之后,我们的函数将等待 `response.json()` 的调用完成
// `response.json()` 调用将返回 JSON 对象或抛出一个错误
const
json
=
await
response
.
json
();
console
.
log
(
json
[
0
].
name
);
}
catch
(
error
)
{
console
.
error
(
`无法获取产品列表:
${
error
}
`
);
}
}
}
// await fetchAPI示例
</
script
>
</
script
>
<
template
>
<
template
>
<div
class=
"fit"
>
<div
class=
"fit"
>
<div
class=
"q-mb-md"
>
async await return
</div>
<div
class=
"q-mb-md"
>
async await return
</div>
<div
class=
"q-mb-md"
>
<a
href=
"https://blog.csdn.net/huchaoyue_/article/details/127686795"
target=
"_blank"
>
详细内容请查看CSDN
</a
>
</div>
<div
class=
"content q-gutter-md"
>
<div
class=
"content q-gutter-md"
>
<q-card
class=
"my-card bg-primary text-white"
>
<q-card
class=
"my-card bg-primary text-white"
>
<q-card-section>
<q-card-section>
...
@@ -129,6 +172,20 @@ function fetchApi() {
...
@@ -129,6 +172,20 @@ function fetchApi() {
</div>
</div>
</q-card-section>
</q-card-section>
</q-card>
</q-card>
<q-card
class=
"my-card bg-pink-3 text-white"
>
<q-card-section>
<div
class=
"q-mb-md q-gutter-sm"
>
<q-btn
no-caps
color=
"white"
text-color=
"pink-3"
label=
"async await"
@
click=
"fetchProducts"
/>
</div>
</q-card-section>
</q-card>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
...
...
src/modules/page6/element/equipment/EquipmentPage.vue
View file @
5b4aac46
...
@@ -15,17 +15,32 @@ const slide = ref('1');
...
@@ -15,17 +15,32 @@ const slide = ref('1');
watch
(
watch
(
()
=>
props
.
list
,
()
=>
props
.
list
,
()
=>
{
(
newVal
,
oldVal
)
=>
{
listChange
();
listChange
(
newVal
,
oldVal
);
}
}
);
);
function
listChange
()
{
function
listChange
(
newVal
:
any
,
oldVal
:
any
)
{
console
.
log
(
'999'
,
props
.
list
);
console
.
log
(
'newVal'
,
newVal
.
length
,
'oldVal'
,
oldVal
.
length
);
if
(
oldVal
.
length
<
newVal
.
length
&&
oldVal
.
length
===
1
)
{
setTimeout
(()
=>
{
slide
.
value
=
'2'
;
},
props
.
autoplay
);
}
if
(
newVal
.
length
<
Number
(
slide
.
value
))
{
slide
.
value
=
'1'
;
}
}
function
clickPoint
(
value
:
string
)
{
if
(
value
!==
slide
.
value
)
{
slide
.
value
=
value
;
}
}
}
</
script
>
</
script
>
<
template
>
<
template
>
<div
class=
"my-carousel-box"
>
<div
class=
"my-carousel-box"
>
<template
v-if=
"props.list.length > 0"
>
<div
class=
"content"
>
<div
class=
"content"
>
<q-carousel
<q-carousel
v-model=
"slide"
v-model=
"slide"
...
@@ -33,25 +48,37 @@ function listChange() {
...
@@ -33,25 +48,37 @@ function listChange() {
transition-next=
"slide-left"
transition-next=
"slide-left"
animated
animated
infinite
infinite
:keep-alive=
"false"
:autoplay=
"props.autoplay"
class=
"my-carousel"
class=
"my-carousel"
>
>
<q-carousel-slide
name=
"1"
class=
"my-carousel-slide"
>
<q-carousel-slide
<div
class=
"item"
>
:name=
"String(index + 1)"
<div
class=
"item-equipment"
>
class=
"my-carousel-slide"
v-for=
"(item, index) in props.list"
:key=
"index"
>
<div
class=
"item-carousel-content"
>
<div
class=
"item"
v-for=
"(ele, el_index) in item"
:key=
"el_index"
>
<div
class=
"pic"
></div>
<div
class=
"pic"
></div>
<div
class=
"item-name"
>
Z01
</div>
<div
class=
"item-name"
:style=
"
{ backgroundColor: ele.color }">
{{
ele
.
code
}}
</div>
</div>
</div>
</div>
</div>
</q-carousel-slide>
<q-carousel-slide
name=
"2"
class=
"my-carousel-slide"
>
<div
class=
"item"
>
888
</div>
</q-carousel-slide>
<q-carousel-slide
name=
"3"
class=
"my-carousel-slide"
>
<div
class=
"item"
>
999
</div>
</q-carousel-slide>
</q-carousel-slide>
</q-carousel>
</q-carousel>
</div>
</div>
<div
class=
"points"
>
导航
</div>
<div
class=
"points"
>
<div
class=
"cursor-pointer"
:class=
"
{ active: slide === String(index + 1) }"
v-for="(i, index) in props.list"
:key="index"
@click="clickPoint(String(index + 1))"
>
</div>
</div>
</
template
>
</div>
</div>
</template>
</template>
...
@@ -73,7 +100,7 @@ function listChange() {
...
@@ -73,7 +100,7 @@ function listChange() {
.my-carousel-slide
{
.my-carousel-slide
{
padding
:
0
!
important
;
padding
:
0
!
important
;
}
}
.item
{
.item
-carousel-content
{
width
:
100%
;
width
:
100%
;
height
:
100%
;
height
:
100%
;
overflow
:
hidden
;
overflow
:
hidden
;
...
@@ -82,14 +109,15 @@ function listChange() {
...
@@ -82,14 +109,15 @@ function listChange() {
display
:
grid
;
display
:
grid
;
grid-template-columns
:
repeat
(
5
,
1fr
);
grid-template-columns
:
repeat
(
5
,
1fr
);
grid-template-rows
:
repeat
(
2
,
1fr
);
grid-template-rows
:
repeat
(
2
,
1fr
);
// grid-template-columns: repeat(2, 1fr);
// grid-template-rows: repeat(2, 1fr);
grid-gap
:
5px
5px
;
}
}
.item-equipment
{
.item
{
border
:
1px
solid
red
;
display
:
flex
;
display
:
flex
;
flex-flow
:
column
nowrap
;
flex-flow
:
column
nowrap
;
.pic
{
.pic
{
width
:
100%
;
width
:
100%
;
background-color
:
pink
;
background-image
:
url('https://img0.baidu.com/it/u=925843206,3288141497&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1666803600&t=81f620f962ec6a70673c05d6a55328b5')
;
background-image
:
url('https://img0.baidu.com/it/u=925843206,3288141497&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1666803600&t=81f620f962ec6a70673c05d6a55328b5')
;
background-size
:
100%
100%
;
background-size
:
100%
100%
;
flex
:
1
;
flex
:
1
;
...
@@ -99,7 +127,26 @@ function listChange() {
...
@@ -99,7 +127,26 @@ function listChange() {
display
:
flex
;
display
:
flex
;
justify-content
:
center
;
justify-content
:
center
;
align-items
:
center
;
align-items
:
center
;
background-color
:
yellow
;
}
}
}
}
.points
{
padding
:
5px
;
display
:
flex
;
flex-flow
:
row
wrap
;
justify-content
:
center
;
align-items
:
center
;
}
// 小圆点
.cursor-pointer
{
height
:
4px
;
width
:
40px
;
margin-right
:
5px
;
border-radius
:
50px
;
background-color
:
rgba
(
$color
:
#3ecdff
,
$alpha
:
0
.3
);
cursor
:
pointer
;
transition
:
all
0
.5s
;
}
.active
{
background-color
:
#3ecdff
;
}
</
style
>
</
style
>
src/modules/page6/element/equipment/IndexPage.vue
View file @
5b4aac46
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
-->
-->
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
reactive
,
onMounted
}
from
'vue'
;
import
{
reactive
,
onMounted
}
from
'vue'
;
import
{
machineList1
}
from
'../../config'
;
import
{
machineList1
,
machineList2
}
from
'../../config'
;
import
EquipmentPage
from
'./EquipmentPage.vue'
;
import
EquipmentPage
from
'./EquipmentPage.vue'
;
const
state
=
reactive
({
const
state
=
reactive
({
...
@@ -17,18 +17,22 @@ onMounted(() => {
...
@@ -17,18 +17,22 @@ onMounted(() => {
});
});
function
handleMachineList
(
data
:
any
)
{
function
handleMachineList
(
data
:
any
)
{
const
step
=
3
;
const
step
=
10
;
// 10个一组
const
length
=
data
.
length
;
const
length
=
data
.
length
;
const
divisionRes
=
division
(
length
,
step
);
const
divisionRes
=
division
(
length
,
step
);
console
.
log
(
divisionRes
);
let
DATA
=
JSON
.
parse
(
JSON
.
stringify
(
data
));
let
DATA
=
JSON
.
parse
(
JSON
.
stringify
(
data
));
let
arr
=
[]
as
any
;
let
arr
=
[]
as
any
;
for
(
let
i
=
0
;
i
<
divisionRes
.
int
;
i
++
)
{
for
(
let
i
=
0
;
i
<
divisionRes
.
int
;
i
++
)
{
return
;
const
newArr
=
DATA
.
slice
(
i
*
step
,
(
i
+
1
)
*
step
);
arr
.
push
(
newArr
);
}
const
last
=
divisionRes
.
int
*
step
;
if
(
DATA
.
slice
(
last
).
length
>
0
)
{
arr
.
push
(
DATA
.
slice
(
last
));
}
}
return
DATA
;
return
arr
;
}
}
// 取整 取余
// 取整 取余
...
@@ -40,9 +44,28 @@ function division(n: number, m: number) {
...
@@ -40,9 +44,28 @@ function division(n: number, m: number) {
int
,
int
,
};
};
}
}
function
changeData1
()
{
state
.
list
=
handleMachineList
(
machineList2
);
}
function
resetData
()
{
state
.
list
=
handleMachineList
(
machineList1
);
}
function
changeTime1
()
{
state
.
autoplay
=
1000
;
}
function
changeTime2
()
{
state
.
autoplay
=
5000
;
}
</
script
>
</
script
>
<
template
>
<
template
>
<div>
机台列表
</div>
<div>
机台列表
</div>
<div>
<q-btn
label=
"改变数据1"
color=
"primary"
@
click=
"changeData1"
/>
<q-btn
label=
"重置"
color=
"primary"
@
click=
"resetData"
/>
<q-btn
label=
"改变轮播时间1000"
color=
"orange"
@
click=
"changeTime1"
/>
<q-btn
label=
"改变轮播时间5000"
color=
"orange"
@
click=
"changeTime2"
/>
</div>
<div
class=
"my-warp-box"
>
<div
class=
"my-warp-box"
>
<equipment-page
:list=
"state.list"
:autoplay=
"state.autoplay"
/>
<equipment-page
:list=
"state.list"
:autoplay=
"state.autoplay"
/>
</div>
</div>
...
@@ -53,6 +76,6 @@ function division(n: number, m: number) {
...
@@ -53,6 +76,6 @@ function division(n: number, m: number) {
width
:
500px
;
width
:
500px
;
height
:
300px
;
height
:
300px
;
border
:
1px
solid
red
;
border
:
1px
solid
red
;
background-color
:
yellowgreen
;
background-color
:
black
;
}
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment