Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
new_taobao
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wildfirecode13
new_taobao
Commits
75546213
Commit
75546213
authored
Sep 22, 2020
by
Edwise
🍷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
10126358
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
235 additions
and
237 deletions
+235
-237
pagecanvas.js
taobao_mini/client/pages/pagecanvas/pagecanvas.js
+235
-237
No files found.
taobao_mini/client/pages/pagecanvas/pagecanvas.js
View file @
75546213
'use strict'
;
import
{
Main
Main
}
from
'./output'
;
import
API
from
'../../api'
;
import
mock
from
'../../mock'
;
const
app
=
getApp
();
const
{
tbcc
tbcc
}
=
app
;
const
{
commonToast
,
getAuthUserInfo
,
navigateToOutside
,
getSystemInfo
commonToast
,
getAuthUserInfo
,
navigateToOutside
,
getSystemInfo
}
=
tbcc
.
tb
;
const
checkSystem
=
async
()
=>
{
const
{
version
}
=
await
getSystemInfo
();
console
.
log
(
'version'
,
version
);
return
tbcc
.
utils
.
versionCompare
(
version
,
'9.8.0'
);
const
{
version
}
=
await
getSystemInfo
();
console
.
log
(
'version'
,
version
);
return
tbcc
.
utils
.
versionCompare
(
version
,
'9.8.0'
);
}
Page
({
data
:
{
messageModalVisible
:
false
,
messageModalData
:
{},
ruleModalVisible
:
false
,
levelupModalVisible
:
false
},
data
:
{
messageModalVisible
:
false
,
messageModalData
:
{},
ruleModalVisible
:
false
,
levelupModalVisible
:
false
,
selectcatModalVisible
:
false
,
catnameModalVisible
:
false
},
onLoad
(
props
)
{
this
.
setData
({});
onLoad
(
props
)
{
this
.
setData
({});
checkSystem
().
then
(
r
=>
{
if
(
!
r
)
{
my
.
showToast
({
content
:
"请升级最新版本的淘宝"
,
duration
:
5000
});
}
checkSystem
().
then
(
r
=>
{
if
(
!
r
)
{
my
.
showToast
({
content
:
"请升级最新版本的淘宝"
,
duration
:
5000
});
}
});
},
onReady
()
{
console
.
log
(
'on ready'
)
//授权和登录先搞
// this.getAuth();
setTimeout
(()
=>
{
// this.onMessage({
// data: {
// netName: 'mine.showModal',
// parameter: {
// name: 'levelupModal'
// }
// }
// });
// this.onMessage({
// data: {
// netName: 'mine.showModal',
// parameter: {
// name: 'messageModal',
// data: { catName: '喵喵1122' }
// }
// }
// });
},
// this.onMessage({
// data: {
// netName: 'mine.navigateToPage',
// parameter: {
// name: 'pageshop'
// }
// }
// });
},
1000
);
},
onReady
()
{
console
.
log
(
'on ready'
)
var
that
=
this
;
setTimeout
(()
=>
{
var
parameter
=
{
name
:
"catnameModal"
}
var
data
=
{
netName
:
"mine.showModal"
,
parameter
}
that
.
onMessage
({
data
:
data
})
},
2000
)
//授权和登录先搞
// this.getAuth();
my
.
__onMessage__
=
(
e
)
=>
{
this
.
onMessage
(
e
)
}
},
init
()
{
console
.
log
(
'do init'
);
this
.
spark_startEngine
();
},
init
()
{
console
.
log
(
'do init'
);
this
.
spark_startEngine
();
},
spark_startEngine
()
{
console
.
log
(
'spark_startEngine'
)
var
self
=
this
;
my
.
createCanvas
({
id
:
'canvas'
,
success
:
ccc
=>
{
const
dpr
=
my
.
getSystemInfoSync
().
pixelRatio
;
const
windowWidth
=
my
.
getSystemInfoSync
().
windowWidth
;
const
windowHeight
=
my
.
getSystemInfoSync
().
windowHeight
;
ccc
.
width
=
windowWidth
*
dpr
+
dpr
;
//重新修改会有误差
spark_startEngine
()
{
console
.
log
(
'spark_startEngine'
)
var
self
=
this
;
my
.
createCanvas
({
id
:
'canvas'
,
success
:
ccc
=>
{
const
dpr
=
my
.
getSystemInfoSync
().
pixelRatio
;
const
windowWidth
=
my
.
getSystemInfoSync
().
windowWidth
;
const
windowHeight
=
my
.
getSystemInfoSync
().
windowHeight
;
ccc
.
width
=
windowWidth
*
dpr
+
dpr
;
//重新修改会有误差
ccc
.
height
=
windowHeight
*
dpr
+
dpr
;
ccc
.
height
=
windowHeight
*
dpr
+
dpr
;
if
(
!
this
.
main
)
{
this
.
main
=
new
Main
(
ccc
);
//添加事件,为了和main里的通信
app
.
canvasMain
=
this
.
main
;
if
(
!
this
.
main
)
{
this
.
main
=
new
Main
(
ccc
);
//添加事件,为了和main里的通信
app
.
canvasMain
=
this
.
main
;
this
.
main
.
addGlobalEvent
(
"onMessage"
,
self
.
onMessage
,
self
);
this
.
main
.
addGlobalEvent
(
"showToast"
,
self
.
showToast
,
self
);
}
}
});
},
this
.
main
.
addGlobalEvent
(
"onMessage"
,
self
.
onMessage
,
self
);
this
.
main
.
addGlobalEvent
(
"showToast"
,
self
.
showToast
,
self
);
}
}
});
},
onCanvasReady
()
{
console
.
log
(
'onCanvasReady'
)
//授权和登录先搞
checkSystem
().
then
(
r
=>
{
if
(
r
)
{
this
.
getAuth
();
}
});
},
onCanvasReady
()
{
console
.
log
(
'onCanvasReady'
)
//授权和登录先搞
checkSystem
().
then
(
r
=>
{
if
(
r
)
{
this
.
getAuth
();
}
});
},
showToast
(
e
)
{
my
.
showToast
({
content
:
e
.
data
||
"网络异常,请稍后重试~"
,
duration
:
2000
});
},
showToast
(
e
)
{
my
.
showToast
({
content
:
e
.
data
||
"网络异常,请稍后重试~"
,
duration
:
2000
});
},
postMessage
(
netName
,
data
)
{
this
.
main
&&
this
.
main
.
dispatchGlobalEvent
({
type
:
netName
},
data
);
//以防复用事件event串了,就用这种方式
},
postMessage
(
netName
,
data
)
{
this
.
main
&&
this
.
main
.
dispatchGlobalEvent
({
type
:
netName
},
data
);
//以防复用事件event串了,就用这种方式
},
//和main通信的方法,接收main的信息
onMessage
(
e
)
{
//接口名字
let
netName
=
e
.
data
.
netName
;
//接口参数
//和main通信的方法,接收main的信息
onMessage
(
e
)
{
//接口名字
let
netName
=
e
.
data
.
netName
;
//接口参数
let
parameter
=
e
.
data
.
parameter
;
//暂时发现3个需要用户操作的接口
//定制的授权
let
parameter
=
e
.
data
.
parameter
;
//暂时发现3个需要用户操作的接口
//定制的授权
if
(
netName
.
indexOf
(
"mine"
)
==
0
)
{
var
data
=
{
success
:
true
};
if
(
netName
.
indexOf
(
"mine"
)
==
0
)
{
var
data
=
{
success
:
true
};
switch
(
netName
)
{
case
"mine.getAppData"
:
//获取信息
data
=
{
success
:
true
,
data
:
{
activityId
:
app
.
activityId
,
nickName
:
app
.
nickName
,
avatar
:
app
.
avatar
,
openId
:
app
.
openId
}
};
break
;
case
"mine.navigateToPage"
:
//切换page
data
=
{
success
:
true
,
data
:
{}
};
my
.
navigateTo
({
url
:
`/pages/
${
parameter
.
name
}
/
${
parameter
.
name
}
`
});
break
;
case
"mine.showModal"
:
//切换page
data
=
{
success
:
true
,
data
:
{}
};
const
key
=
`
${
parameter
.
name
}
Visible`
;
const
datakey
=
`
${
parameter
.
name
}
Data`
;
const
toSetData
=
{};
toSetData
[
key
]
=
true
;
toSetData
[
datakey
]
=
parameter
.
data
;
this
.
setData
(
toSetData
);
break
;
case
'test'
:
console
.
log
(
'测试一下'
,
parameter
.
hint
);
break
;
switch
(
netName
)
{
case
"mine.getAppData"
:
//获取信息
data
=
{
success
:
true
,
data
:
{
activityId
:
app
.
activityId
,
nickName
:
app
.
nickName
,
avatar
:
app
.
avatar
,
openId
:
app
.
openId
}
};
break
;
case
"mine.navigateToPage"
:
//切换page
data
=
{
success
:
true
,
data
:
{}
};
my
.
navigateTo
({
url
:
`/pages/
${
parameter
.
name
}
/
${
parameter
.
name
}
`
});
break
;
case
"mine.showModal"
:
//切换page
data
=
{
success
:
true
,
data
:
{}
};
const
key
=
`
${
parameter
.
name
}
Visible`
;
const
datakey
=
`
${
parameter
.
name
}
Data`
;
const
toSetData
=
{};
toSetData
[
key
]
=
true
;
toSetData
[
datakey
]
=
parameter
.
data
;
this
.
setData
(
toSetData
);
break
;
case
'test'
:
console
.
log
(
'测试一下'
,
parameter
.
hint
);
break
;
}
this
.
postMessage
(
netName
,
data
);
}
else
{
const
{
function
:
fc
}
=
app
.
cloud
;
const
[
myCloudName
,
handler
]
=
netName
.
split
(
"."
);
//待写,
this
.
postMessage
(
netName
,
data
);
}
else
{
const
{
function
:
fc
}
=
app
.
cloud
;
const
[
myCloudName
,
handler
]
=
netName
.
split
(
"."
);
//待写,
parameter
.
activityId
=
app
.
activityId
;
fc
.
invoke
(
myCloudName
,
parameter
,
handler
).
then
(
res
=>
{
this
.
postMessage
(
netName
,
res
);
});
}
},
if
(
app
.
requestType
==
'yapi'
)
{
console
.
log
(
'mock[handler]'
,
mock
[
handler
])
this
.
postMessage
(
netName
,
mock
[
handler
]);
return
;
}
//鼠标事件
onMouseEvent
(
e
)
{
if
(
this
.
main
)
this
.
main
.
stage
.
onMouseEvent
(
e
);
},
parameter
.
activityId
=
app
.
activityId
;
fc
.
invoke
(
myCloudName
,
parameter
,
handler
).
then
(
res
=>
{
this
.
postMessage
(
netName
,
res
);
});
}
},
onShow
()
{
// 页面显示
if
(
this
.
main
)
{
this
.
main
.
run
();
this
.
main
.
dispatchGlobalEvent
(
"onShow"
);
}
},
//鼠标事件
onMouseEvent
(
e
)
{
if
(
this
.
main
)
this
.
main
.
stage
.
onMouseEvent
(
e
);
},
onHide
()
{
// 页面隐藏
if
(
this
.
main
)
{
this
.
main
.
pause
();
this
.
main
.
dispatchGlobalEvent
(
"onHide
"
);
}
},
onShow
()
{
// 页面显示
if
(
this
.
main
)
{
this
.
main
.
run
();
this
.
main
.
dispatchGlobalEvent
(
"onShow
"
);
}
},
/**
* 获取用户授权信息
*/
async
getAuth
()
{
const
userInfo
=
await
getAuthUserInfo
().
catch
(
err
=>
{
console
.
log
(
'未授权成功'
,
err
);
});
if
(
userInfo
)
{
console
.
log
(
'userInfo'
,
userInfo
);
const
{
nickName
,
avatar
}
=
userInfo
;
app
.
nickName
=
nickName
;
app
.
avatar
=
avatar
;
this
.
login
();
}
},
/**
* 登录接口
*/
async
login
()
{
const
{
nickName
,
avatar
}
=
app
;
const
{
success
}
=
await
API
.
login
({
userNick
:
nickName
,
avatar
}).
catch
(
res
=>
{
commonToast
(
res
&&
res
.
message
);
})
||
{};
onHide
()
{
// 页面隐藏
if
(
this
.
main
)
{
this
.
main
.
pause
();
this
.
main
.
dispatchGlobalEvent
(
"onHide"
);
}
},
if
(
success
)
{
this
.
init
();
}
},
closeLevelupModal
()
{
this
.
setData
({
levelupModalVisible
:
false
});
},
closeRuleModal
()
{
this
.
setData
({
ruleModalVisible
:
false
});
},
closeMessageModal
()
{
this
.
setData
({
messageModalVisible
:
false
});
/**
* 获取用户授权信息
*/
async
getAuth
()
{
const
userInfo
=
await
getAuthUserInfo
().
catch
(
err
=>
{
console
.
log
(
'未授权成功'
,
err
);
});
if
(
userInfo
)
{
console
.
log
(
'userInfo'
,
userInfo
);
const
{
nickName
,
avatar
}
=
userInfo
;
app
.
nickName
=
nickName
;
app
.
avatar
=
avatar
;
this
.
init
();
// this.login();
}
},
/**
* 登录接口
*/
async
login
()
{
const
{
nickName
,
avatar
}
=
app
;
const
{
success
}
=
await
API
.
login
({
userNick
:
nickName
,
avatar
}).
catch
(
res
=>
{
commonToast
(
res
&&
res
.
message
);
})
||
{};
});
\ No newline at end of file
if
(
success
)
{
this
.
init
();
}
},
closeLevelupModal
()
{
this
.
setData
({
levelupModalVisible
:
false
});
},
closeRuleModal
()
{
this
.
setData
({
ruleModalVisible
:
false
});
},
closeMessageModal
()
{
this
.
setData
({
messageModalVisible
:
false
});
},
closeCatnameModal
()
{
this
.
setData
({
catnameModalVisible
:
false
})
},
closeSelectcatModal
()
{
this
.
setData
({
selectcatModalVisible
:
false
})
},
});
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