Compare commits
51
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b4842b261 | ||
|
|
691ac03cfd | ||
|
|
5e4c4fdd22 | ||
|
|
de67ab0d68 | ||
|
|
121b620312 | ||
|
|
49ed8e588a | ||
|
|
22af68428f | ||
|
|
4f49012bb6 | ||
|
|
73563de980 | ||
|
|
eb77678686 | ||
|
|
fc6fee74b0 | ||
|
|
9543fa8409 | ||
|
|
fadbc4dc72 | ||
|
|
ad4570dae0 | ||
|
|
8d248466eb | ||
|
|
bfa5ed0e3a | ||
|
|
582c8446e2 | ||
|
|
0fc0fa932a | ||
|
|
98f4236c35 | ||
|
|
b37977418a | ||
|
|
7a78cf0594 | ||
|
|
af68984caa | ||
|
|
623307ef2b | ||
|
|
14b03af584 | ||
|
|
c3773a3c71 | ||
|
|
0140136a0b | ||
|
|
41519b78e4 | ||
|
|
9b4cfe95a5 | ||
|
|
6937b93517 | ||
|
|
e1d4745ecb | ||
|
|
faa7ed0b0e | ||
|
|
77370eb3eb | ||
|
|
82f438056e | ||
|
|
8d08589b4c | ||
|
|
af2d88f651 | ||
|
|
0528c2865d | ||
|
|
df10c22a8d | ||
|
|
773da154ff | ||
|
|
55d52f446f | ||
|
|
da658cb371 | ||
|
|
ce7d6c74f0 | ||
|
|
7fa3a215cf | ||
|
|
cea68f5145 | ||
|
|
18b167266d | ||
|
|
84b927a71b | ||
|
|
004ea1895b | ||
|
|
0f70998a5f | ||
|
|
d02cc5db3b | ||
|
|
2a85beba68 | ||
|
|
93d47426d8 | ||
|
|
cf88f314f1 |
+6
-1
@@ -12,4 +12,9 @@ $RECYCLE.BIN/
|
||||
|
||||
# Node.js
|
||||
node_modules/
|
||||
.idea
|
||||
|
||||
# wxss
|
||||
*.wxss
|
||||
|
||||
# idea
|
||||
.idea
|
||||
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,102 @@
|
||||
# 第三代掌上教务处小程序
|
||||
|
||||
掌上教务处作为工业大学的社区开源项目,自从2017年开始已有近5年岁月,在无数同学的贡献之下,为大家打造便捷的校园服务。
|
||||
|
||||
__*!!!警告!!!*__
|
||||
|
||||
请在主仓库提交代码,而非镜像仓库!在镜像仓库提交的代码将会在同步时被覆盖!
|
||||
|
||||
主仓库: http://git.mrkbear.com/MrKBear/mini-dlpu-v3
|
||||
|
||||
镜像仓库: https://github.com/Mr-k-bear/mini-dlpu-v3
|
||||
|
||||
## 目录
|
||||
|
||||
- [社区介绍](#小程序社区)
|
||||
- [项目设计](#第三代小程序)
|
||||
- [贡献规范](#社区贡献规范)
|
||||
- [入门文档(等待撰写)](#第三代掌上教务处小程序)
|
||||
- [设计架构(等待撰写)](#第三代掌上教务处小程序)
|
||||
|
||||
## 小程序社区
|
||||
|
||||
掌上教务处小程序诞生于2017年中旬,此时微信小程序刚刚公测。
|
||||
|
||||
2017年,信息学院吴学长因兴趣设计了一款方便课表查询的小工具,在班级范围内使用,就这样掌上教务处诞生了。
|
||||
|
||||
随着大家的好评和认可,小程序使用范围慢慢扩大,从班级到专业到学院,同时,吴学长也面临着越来越大的责任和压力。
|
||||
|
||||
正当小程序维护困难之际,很多热心的同学,为吴学长贡献代码,创意,UI设计图纸,从此"成绩查询"、"考试日程"、"空教室"这样的小功能如雨后春笋,慢慢诞生......
|
||||
|
||||
此时,作为大家努力的结晶,小程序开放了源代码。
|
||||
|
||||
> PS:
|
||||
> 哈哈,你可能会好奇为什么小程序的LOGO看起来很奇怪,其实这个 LOGO 是一个热心的同学在2018年贡献的,为了纪念小程序最初的贡献者们一直沿用至今。
|
||||
|
||||
毕竟服务器是有成本的,随着用户的增多,吴学长自掏腰包租赁的服务器,已不再能维持小程序流畅运行,小程序再次陷入困境。
|
||||
|
||||
这时有其他热心同学,赞助了自己租赁的服务器...
|
||||
越来越多,越来越多,不愿透露名字的热心人给服务器取了有趣的名字。
|
||||
|
||||
就这样,"笔芯"、"妲己"、"猪蹄"、"MOS"...一台台自租赁的服务器支撑起了大家的日常使用。
|
||||
|
||||
> PS:
|
||||
> 如果你愿意考古的话,去看看老版本小程序的切换服务器页面,它们就这样静静的挺拨在那里,为大家默默的服务着...
|
||||
|
||||
后来随着开发者们的加入,小程序有了更多的功能、更好的技术、更高的性能。
|
||||
|
||||
2019年期间,在吴学长、秦学长、梁学长、潘学姐、隋学长以及其他社区贡献者的共同努力下,第二代小程序诞生了,并更名为"掌上教务处"。
|
||||
|
||||
重构后的小程序,犹如脱胎换骨,性能提高很多倍,得到了很多同学的关注,用户数量达到19000人。
|
||||
|
||||
2020年随着小程序的稳定,大家也已经习惯了目前的设计,但是小程序仍有部分设计缺陷,导致可拓展性降低,难以拓展新功能,无法和其他商业产品竞争。
|
||||
|
||||
老一代社区贡献者们开始逐渐毕业,社区迎来前所未有的空窗期。
|
||||
社区团队逐渐消退,仅剩梁学长、秦学长在日常爱心维护小程序代码,供大家日常使用。
|
||||
|
||||
## 第三代小程序
|
||||
|
||||
突破内容:
|
||||
|
||||
1. 小程序在技术上突破更高的性能瓶颈
|
||||
|
||||
2. 更漂亮的UI,和更好的交互体验
|
||||
|
||||
3. 更好的拓展性,加入更多大家喜欢的功能
|
||||
|
||||
新功能:
|
||||
|
||||
1. 正在讨论设计,等待你的建议...
|
||||
|
||||
## 社区贡献规范
|
||||
|
||||
请仔细阅读!
|
||||
### 项目贡献流程
|
||||
|
||||
请先邮件联系 ```mrkbear@mrkbear.com``` 获得 Gitea 平台账号
|
||||
|
||||
在仓库中创建自己的分支,分支命名规范为 ```dev-你的昵称```,例如 ```dev-mrkbear```
|
||||
|
||||
克隆此储库,在本地 ```git checkout dev-你的昵称``` 到自己的分支,进行改动。
|
||||
|
||||
开发完成后 ```git push``` 到自己的远程分支,并发起合并请求到 ```master``` 分支
|
||||
|
||||
发起合并请求时,需要指派给 ```MrKBear``` 进行代码审核,审核通过后,代码将完成合并。
|
||||
|
||||
### 注意事项
|
||||
|
||||
1. ```master``` 分支处于保护状态,仅通过合并请求进行修改
|
||||
|
||||
2. 代码提交时,请使用清晰明确的 ```message```
|
||||
|
||||
正例: ```Add timetable page``` 反例: ```阿巴阿巴阿巴阿巴```
|
||||
|
||||
3. 请勿将任何个人隐私信息以任何方式,放入代码中
|
||||
|
||||
4. 为保证 CI/CD,提交代码前必须保证编译可以通过
|
||||
|
||||
5. 一个文件不要超过 1000 行代码,尽量保证代码可读性
|
||||
|
||||
## 贡献者
|
||||
|
||||
@MrKBear (熊鲜森)
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
$theme-color-blue: #3EA3D8;
|
||||
$theme-color-red: #FF9393;
|
||||
|
||||
$theme-color-light-layout: #F8F8F8;
|
||||
$theme-color-light-background: #f4f0f1;
|
||||
$theme-color-light-title: rgba(0, 0, 0, .65);
|
||||
$theme-color-light-text: rgba(0, 0, 0, .55);
|
||||
|
||||
$theme-color-dark-layout: #191919;
|
||||
$theme-color-dark-background: #1f1f1f;
|
||||
$theme-color-dark-title: rgba(255, 255, 255, .65);
|
||||
$theme-color-dark-text: rgba(255, 255, 255, .55);
|
||||
|
||||
$black-filter: brightness(0) opacity(.65);
|
||||
$white-filter: brightness(100) opacity(.65);
|
||||
$blue-filter: opacity(.65);
|
||||
|
||||
|
||||
|
||||
page {
|
||||
background-color: #f4f0f1;
|
||||
color: $theme-color-light-text;
|
||||
font-weight: 500;
|
||||
font-size: .9em;
|
||||
font-family: Hiragino Sans GB, MicroSoft YaHei;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark){
|
||||
page {
|
||||
background-color: #1f1f1f;
|
||||
color: $theme-color-dark-text;
|
||||
}
|
||||
}
|
||||
+23
-21
@@ -1,27 +1,29 @@
|
||||
import {Logger} from "./utils/Logger";
|
||||
import * as label from "./utils/LogLabel";
|
||||
import { IAppAPIParam } from "./core/Api";
|
||||
import { IAppStorageParam, Storage, IStorageData } from "./core/Storage";
|
||||
import { Logger, LevelLogLabel, LifeCycleLogLabel } from "./core/Logger";
|
||||
|
||||
|
||||
App<IAppOption>({
|
||||
App<IAppAPIParam & IAppStorageParam>({
|
||||
|
||||
/**
|
||||
* 全局数据
|
||||
*/
|
||||
globalData: {},
|
||||
/**
|
||||
* API 模块需要的全局数据
|
||||
* 参见 "/core/Api"
|
||||
*/
|
||||
api: {
|
||||
nextId: 1,
|
||||
pool: new Set()
|
||||
},
|
||||
|
||||
/**
|
||||
* 小程序加载时
|
||||
*/
|
||||
onLaunch() {
|
||||
/**
|
||||
* 存储缓存键值
|
||||
*/
|
||||
storage: new Map<string, Storage<IStorageData>>(),
|
||||
|
||||
Logger.log("hh",
|
||||
label.FatalLabel,label.ErrorLabel,label.WarnLabel,
|
||||
label.InfoLabel,label.DebugLabel,label.TraceLabel
|
||||
);
|
||||
|
||||
Logger.logM(
|
||||
[label.FatalLabel,label.ErrorLabel,label.WarnLabel,
|
||||
label.InfoLabel,label.DebugLabel,label.TraceLabel], "hh"
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 小程序加载时
|
||||
*/
|
||||
onLaunch() {
|
||||
Logger.log("小程序启动...",
|
||||
LevelLogLabel.InfoLabel, LifeCycleLogLabel.OnLaunchLabel);
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,556 @@
|
||||
import { Emitter } from "./Emitter";
|
||||
import { Logger, LogLabel, LevelLogLabel, colorRadio, StatusLabel } from "./Logger";
|
||||
interface IAppAPIParam {
|
||||
api: {
|
||||
|
||||
/**
|
||||
* API 编号
|
||||
*/
|
||||
nextId: number;
|
||||
|
||||
/**
|
||||
* 请求池
|
||||
* 保存正在等待的 API 请求
|
||||
*/
|
||||
pool: Set<API<IAnyData, IAnyData>>;
|
||||
}
|
||||
}
|
||||
|
||||
interface IAnyData {
|
||||
[x:string]: any
|
||||
}
|
||||
|
||||
type IWxRequestOption<O> = WechatMiniprogram.RequestOption<O>;
|
||||
|
||||
type DeepReadonly<T> = {
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 请求参数设置
|
||||
*/
|
||||
type IParamSetting<T extends IAnyData> = {
|
||||
[P in keyof T]: {
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
defaultValue?: T[P],
|
||||
|
||||
/**
|
||||
* ### 数据测试
|
||||
* 1、支持正则表达式测试 \
|
||||
* 2、支持使用 string === string 测试 \
|
||||
* 3、支持使用 number === number 测试 \
|
||||
* 4、支持使用自定义函数测试
|
||||
*/
|
||||
tester?: RegExp | ((data:T[P]) => boolean) | string | number,
|
||||
|
||||
/**
|
||||
* ### 预解析函数
|
||||
* 1、此函数用来处理该键值 \
|
||||
* 2、当返回 undefined 时此键值被遗弃 \
|
||||
* 3、返回值时,此键值被覆盖
|
||||
*
|
||||
* @param data 当前给定数据
|
||||
* @param key 当前给定数据键值
|
||||
* @param all 全部输入数据
|
||||
* @returns 解析结果
|
||||
*/
|
||||
parse?: ((data:T[P], key:string, all:DeepReadonly<Partial<T>>) => T[P] | undefined),
|
||||
|
||||
/**
|
||||
* 是否为请求头数据
|
||||
*/
|
||||
isHeader?: boolean,
|
||||
|
||||
/**
|
||||
* 是否为模板
|
||||
*/
|
||||
isTemplate?: boolean
|
||||
|
||||
/**
|
||||
* 是否可选
|
||||
*/
|
||||
Optional?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
type SuccessCallbackResult<O extends IAnyData> = WechatMiniprogram.RequestSuccessCallbackResult<O>;
|
||||
type GeneralCallbackResult = WechatMiniprogram.GeneralCallbackResult;
|
||||
|
||||
/**
|
||||
* API 事件
|
||||
*/
|
||||
type IAPIEvent<I extends IAnyData, O extends IAnyData> = {
|
||||
|
||||
/**
|
||||
* 当数据初始化事件
|
||||
*/
|
||||
initData: Partial<I>;
|
||||
|
||||
/**
|
||||
* 请求数据解析完成后
|
||||
*/
|
||||
parseRequestData: Partial<I>;
|
||||
|
||||
/**
|
||||
* 请求发送前
|
||||
*/
|
||||
request: IWxRequestOption<O>;
|
||||
|
||||
/**
|
||||
* 成功回调
|
||||
*/
|
||||
success: SuccessCallbackResult<O>;
|
||||
|
||||
/**
|
||||
* 失败回调
|
||||
*/
|
||||
fail: GeneralCallbackResult;
|
||||
|
||||
/**
|
||||
* 完成回调
|
||||
*/
|
||||
complete: GeneralCallbackResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口调用
|
||||
*/
|
||||
class API<I extends IAnyData, O extends IAnyData> extends Emitter<IAPIEvent<I, O>> {
|
||||
|
||||
/**
|
||||
* 基础 URL
|
||||
* TODO: 这里可能涉及负载均衡
|
||||
*/
|
||||
public static get baseUrl():string {
|
||||
return "https://blog.mrkbear.com";
|
||||
}
|
||||
|
||||
public static defaultLogLabel:LogLabel = new LogLabel(
|
||||
`API:API`, colorRadio(200, 120, 222)
|
||||
);
|
||||
|
||||
/**
|
||||
* Logger 使用的标签
|
||||
*/
|
||||
private LogLabel:LogLabel = API.defaultLogLabel;
|
||||
|
||||
/**
|
||||
* Api 唯一 ID
|
||||
*/
|
||||
public key:string = "API";
|
||||
|
||||
/**
|
||||
* API url
|
||||
*/
|
||||
public url:string = "/";
|
||||
|
||||
/**
|
||||
* API 需要的参数列表
|
||||
*/
|
||||
public params:IParamSetting<I> = {} as any;
|
||||
|
||||
/**
|
||||
* API 需要的数据
|
||||
*/
|
||||
public data?:Partial<I>;
|
||||
|
||||
/**
|
||||
* 请求数据
|
||||
*/
|
||||
public requestData?:IWxRequestOption<O>;
|
||||
|
||||
//#region wx.request
|
||||
|
||||
public timeout?:number;
|
||||
public method:HTTPMethod = HTTPMethod.GET;
|
||||
public enableHttp2:boolean = false;
|
||||
public enableQuic:boolean = false;
|
||||
public enableCache:boolean = false;
|
||||
|
||||
/**
|
||||
* 是否自动解析返回的 json
|
||||
* 对应 wx.request 的 dataType
|
||||
*/
|
||||
public jsonParse:boolean = true;
|
||||
|
||||
//#endregion wx.request
|
||||
|
||||
/**
|
||||
* 初始化标签
|
||||
*/
|
||||
public initDebugLabel(key: string) {
|
||||
this.key = key;
|
||||
this.LogLabel = new LogLabel(
|
||||
`API:${ this.key }`, colorRadio(200, 120, 222)
|
||||
);
|
||||
|
||||
// 添加 API 生命周期调试事件
|
||||
this.on("request", (data) => {
|
||||
Logger.logMultiple(
|
||||
[LevelLogLabel.InfoLabel, this.LogLabel, StatusLabel.Pending],
|
||||
`请求发送中: `, data
|
||||
);
|
||||
})
|
||||
|
||||
this.on("success", (data) => {
|
||||
Logger.logMultiple(
|
||||
[LevelLogLabel.InfoLabel, this.LogLabel, StatusLabel.Success],
|
||||
`请求成功: `, data
|
||||
);
|
||||
})
|
||||
|
||||
this.on("fail", (data) => {
|
||||
Logger.logMultiple(
|
||||
[LevelLogLabel.ErrorLabel, this.LogLabel, StatusLabel.Failed],
|
||||
`请求失败: `, data.errMsg
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
* 注意:data 是不安全的,请传入数据副本
|
||||
* @param data API需要的全部数据
|
||||
*/
|
||||
public param(data?: Partial<I>):this {
|
||||
|
||||
this.data = data;
|
||||
|
||||
if (this.data === void 0) {
|
||||
Logger.log(`数据初始化异常: 没有输入 [data] 数据!`,
|
||||
LevelLogLabel.ErrorLabel, this.LogLabel);
|
||||
return this;
|
||||
}
|
||||
|
||||
for (let key in this.params) {
|
||||
|
||||
let data = this.data[key];
|
||||
let { defaultValue, Optional, tester } = this.params[key];
|
||||
|
||||
// 默认值赋予
|
||||
if (data === void 0 && defaultValue !== void 0) {
|
||||
this.data[key] = defaultValue;
|
||||
}
|
||||
|
||||
// 数据存在测试
|
||||
if (data === void 0 && !Optional) {
|
||||
Logger.log(`数据校验异常: 数据 [${key}] 是必须的,但是并没有接收到!`,
|
||||
LevelLogLabel.ErrorLabel, this.LogLabel);
|
||||
}
|
||||
|
||||
// 用户自定义测试
|
||||
if (data !== void 0 && tester !== void 0) {
|
||||
let testRes:boolean = false;
|
||||
|
||||
if (tester instanceof RegExp) {
|
||||
testRes = tester.test(data!);
|
||||
} else if (typeof tester === "string" || typeof tester === "number") {
|
||||
testRes = tester === data;
|
||||
} else if (tester instanceof Function) {
|
||||
testRes = tester(data!);
|
||||
} else {
|
||||
Logger.logMultiple(
|
||||
[LevelLogLabel.ErrorLabel, this.LogLabel],
|
||||
`数据校验异常: [${ key }] 参数存在未知类型的 tester:`, tester
|
||||
);
|
||||
}
|
||||
|
||||
if (!testRes) {
|
||||
Logger.logMultiple(
|
||||
[LevelLogLabel.ErrorLabel, this.LogLabel],
|
||||
`数据校验异常: [${ key }] 参数数据未通过自定义的 tester:`, data
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 触发数据初始化事件
|
||||
this.emit("initData", this.data);
|
||||
|
||||
// 重置请求数据
|
||||
const requestData:IWxRequestOption<O> = this.requestData = {
|
||||
url: API.baseUrl + this.url,
|
||||
data: {}, header: {},
|
||||
timeout: this.timeout,
|
||||
method: this.method,
|
||||
dataType: this.jsonParse ? "json" : undefined,
|
||||
enableHttp2: this.enableHttp2,
|
||||
enableQuic: this.enableQuic,
|
||||
enableCache: this.enableCache
|
||||
};
|
||||
|
||||
// 数据解析
|
||||
for (let key in this.params) {
|
||||
|
||||
let data = this.data[key];
|
||||
let { parse } = this.params[key];
|
||||
|
||||
// 数据预解析
|
||||
if (parse !== void 0) {
|
||||
this.data[key] = parse(data!, key, this.data as DeepReadonly<Partial<I>>);
|
||||
}
|
||||
}
|
||||
|
||||
// 触发数据解析
|
||||
this.emit("parseRequestData", this.data);
|
||||
|
||||
// 数据收集
|
||||
for (let key in this.params) {
|
||||
|
||||
let data = this.data[key];
|
||||
let { isHeader, isTemplate } = this.params[key];
|
||||
|
||||
// 加载数据
|
||||
if (!isTemplate) {
|
||||
if (isHeader) {
|
||||
requestData.header![key] = data;
|
||||
} else {
|
||||
(requestData.data as IAnyData)[key] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求的唯一标识符
|
||||
*/
|
||||
protected id:number = 0;
|
||||
|
||||
/**
|
||||
* 将此请求加入到请求池
|
||||
*/
|
||||
protected addPool():this {
|
||||
|
||||
let app = getApp<IAppAPIParam>();
|
||||
if (app.api.pool.has(this as any)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// 获取标识符
|
||||
if (!this.id) {
|
||||
this.id = app.api.nextId;
|
||||
app.api.nextId ++;
|
||||
}
|
||||
|
||||
app.api.pool.add(this as any);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 pool 中移除
|
||||
*/
|
||||
protected removePool():this {
|
||||
let app = getApp<IAppAPIParam>();
|
||||
app.api.pool.delete(this as any);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 寻找相似的请求
|
||||
*/
|
||||
protected findSameAPI():API<IAnyData, IAnyData> | undefined {
|
||||
|
||||
if (this.requestData === void 0) {
|
||||
Logger.log(`搜索相似请求异常: 没有收集 [requestData] 数据!`,
|
||||
LevelLogLabel.ErrorLabel, this.LogLabel);
|
||||
return;
|
||||
}
|
||||
|
||||
let app = getApp<IAppAPIParam>();
|
||||
let sameAPI:API<IAnyData, IAnyData> | undefined;
|
||||
|
||||
// 判断 API 是否相似
|
||||
app.api.pool.forEach((api) => {
|
||||
if (api === this) return;
|
||||
if (!api.requestData) return;
|
||||
if (api.requestData!.url !== this.requestData!.url) return;
|
||||
if (api.requestData!.method !== this.requestData!.method) return;
|
||||
sameAPI = api;
|
||||
});
|
||||
|
||||
return sameAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记此实例是否已被使用
|
||||
*/
|
||||
private isUsed = false;
|
||||
|
||||
/**
|
||||
* 请求策略
|
||||
*/
|
||||
public policy:RequestPolicy = RequestPolicy.RequestAnyway;
|
||||
|
||||
/**
|
||||
* 运行 API
|
||||
*/
|
||||
public request():this {
|
||||
|
||||
if (this.requestData === void 0) {
|
||||
Logger.log(`请求发送异常: 没有收集 [requestData] 数据!`,
|
||||
LevelLogLabel.ErrorLabel, this.LogLabel);
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.isUsed) {
|
||||
Logger.log(`请求发送异常: 此实例已经使用过了,请使用新实例操作`,
|
||||
LevelLogLabel.ErrorLabel, this.LogLabel);
|
||||
return this;
|
||||
} else {
|
||||
this.isUsed = true;
|
||||
}
|
||||
|
||||
// 加入请求池
|
||||
this.addPool();
|
||||
|
||||
// 发起请求
|
||||
let request = () => {
|
||||
|
||||
// 触发请求发送事件
|
||||
this.emit("request", this.requestData!)
|
||||
|
||||
wx.request<O>({
|
||||
...this.requestData!,
|
||||
success: (e) => {
|
||||
this.emit("success", e);
|
||||
},
|
||||
fail: (e) => {
|
||||
this.emit("fail", e);
|
||||
},
|
||||
complete: (e) => {
|
||||
this.emit("complete", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.policy !== RequestPolicy.RequestAnyway) {
|
||||
let lastAPI = this.findSameAPI();
|
||||
|
||||
if (lastAPI) {
|
||||
|
||||
// 被上次请求阻止
|
||||
if (this.policy === RequestPolicy.BlockByLastRequest) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// 使用上次请求结果
|
||||
if (this.policy === RequestPolicy.useLastRequest) {
|
||||
lastAPI.on("success", (e) => {
|
||||
this.emit("success", e as SuccessCallbackResult<O>);
|
||||
this.emit("complete", {errMsg: e.errMsg});
|
||||
});
|
||||
lastAPI.on("fail", (e) => {
|
||||
this.emit("fail", e);
|
||||
this.emit("complete", {errMsg: e.errMsg});
|
||||
});
|
||||
}
|
||||
|
||||
// 等待上次请求
|
||||
if (this.policy === RequestPolicy.waitLastRequest) {
|
||||
lastAPI.on("success", () => request());
|
||||
lastAPI.on("fail", () => request());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
request();
|
||||
}
|
||||
|
||||
// 监听请求完成后,从 pool 中移除,释放内存
|
||||
this.on("complete", () => {
|
||||
this.removePool();
|
||||
})
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待结果
|
||||
*/
|
||||
public wait(): Promise<IRespondData<O>>;
|
||||
public wait(callBack?: ICallBack<O>): this;
|
||||
public wait(callBack?: ICallBack<O>): Promise<IRespondData<O>> | this {
|
||||
|
||||
// 存在 callback 使用传统回调
|
||||
if (callBack) {
|
||||
callBack.success && this.on("success", callBack.success);
|
||||
callBack.fail && this.on("fail", callBack.fail);
|
||||
callBack.complete && this.on("complete", callBack.complete);
|
||||
return this;
|
||||
}
|
||||
|
||||
// 不存在 callback 使用 Promise 对象
|
||||
else {
|
||||
return new Promise((r) => {
|
||||
this.on("success", r);
|
||||
this.on("fail", r);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动响应数据
|
||||
*/
|
||||
type IRespondData<O extends IAnyData> = Partial<IAPIEvent<IAnyData, O>["success"]> & IAPIEvent<IAnyData, O>["fail"];
|
||||
|
||||
/**
|
||||
* 回调对象
|
||||
*/
|
||||
interface ICallBack<O extends IAnyData> {
|
||||
success?: (data: IAPIEvent<{}, O>["success"]) => any;
|
||||
fail?: (data: IAPIEvent<{}, O>["fail"]) => any;
|
||||
complete?: (data: IAPIEvent<{}, O>["complete"]) => any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request 请求策略
|
||||
* 此策略用于节流
|
||||
*/
|
||||
enum RequestPolicy {
|
||||
|
||||
/**
|
||||
* 什么都不管,发就完了
|
||||
*/
|
||||
RequestAnyway = 1,
|
||||
|
||||
/**
|
||||
* 如果存在等待中的相似请求
|
||||
* 等待相似请求结束后在发送
|
||||
*/
|
||||
waitLastRequest = 2,
|
||||
|
||||
/**
|
||||
* 如果存在等待中的相似请求
|
||||
* 阻止本次请求发送
|
||||
* 将相似请求的结果作为本次请求结果
|
||||
*/
|
||||
useLastRequest = 3,
|
||||
|
||||
/**
|
||||
* 如果存在等待中的相似请求
|
||||
* 阻止本次请求发送
|
||||
*/
|
||||
BlockByLastRequest = 4
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP 请求类型
|
||||
*/
|
||||
enum HTTPMethod {
|
||||
OPTIONS = "OPTIONS",
|
||||
GET = "GET",
|
||||
HEAD = "HEAD",
|
||||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
DELETE = "DELETE",
|
||||
TRACE = "TRACE",
|
||||
CONNECT = "CONNECT"
|
||||
}
|
||||
|
||||
export default API;
|
||||
export { API, IParamSetting, IAppAPIParam, ICallBack, HTTPMethod, RequestPolicy }
|
||||
@@ -10,12 +10,19 @@
|
||||
*/
|
||||
export const LOGGER_CONSOLE:boolean = true;
|
||||
|
||||
/**
|
||||
* 是否在控制台输出时启用标签样式
|
||||
* 如果在手机上调试可以关闭此选项
|
||||
* 因为手机上的控制台无法正确显示样式
|
||||
*/
|
||||
export const LOGGER_STYLE:boolean = true;
|
||||
|
||||
/**
|
||||
* 调试过滤器
|
||||
* 按照 LogLabel 进行过滤
|
||||
*
|
||||
* 注意:
|
||||
* 1、行与行是之间是 || 关系
|
||||
* 1、行与行之间是 || 关系
|
||||
* 2、每行的元素之间是 && 关系
|
||||
* 3、支持正则表达式
|
||||
* 4、字符串使用 === 严格匹配
|
||||
@@ -0,0 +1,87 @@
|
||||
export type EventType = string | symbol;
|
||||
|
||||
// An event handler can take an optional event argument
|
||||
// and should not return a value
|
||||
export type Handler<T = any> = (event: T) => void;
|
||||
|
||||
// An array of all currently registered event handlers for a type
|
||||
export type EventHandlerList<T = any> = Array<Handler<T>>;
|
||||
|
||||
// A map of event types and their corresponding event handlers.
|
||||
export type EventHandlerMap<Events extends Record<EventType, any>> = Map<
|
||||
keyof Events,
|
||||
EventHandlerList<Events[keyof Events]>
|
||||
>;
|
||||
|
||||
export class Emitter<Events extends Record<EventType, any>> {
|
||||
|
||||
/**
|
||||
* A Map of event names to registered handler functions.
|
||||
*/
|
||||
public all: EventHandlerMap<Events>;
|
||||
|
||||
public constructor() {
|
||||
this.all = new Map();
|
||||
}
|
||||
|
||||
public resetAll() {
|
||||
this.all = new Map();
|
||||
}
|
||||
|
||||
public reset<Key extends keyof Events>(type: Key) {
|
||||
this.all!.set(type, [] as EventHandlerList<Events[keyof Events]>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event handler for the given type.
|
||||
* @param {string|symbol} type Type of event to listen for
|
||||
* @param {Function} handler Function to call in response to given event
|
||||
* @memberOf mitt
|
||||
*/
|
||||
public on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>) {
|
||||
const handlers: Array<Handler<Events[Key]>> | undefined = this.all!.get(type);
|
||||
if (handlers) {
|
||||
handlers.push(handler);
|
||||
}
|
||||
else {
|
||||
this.all!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an event handler for the given type.
|
||||
* If `handler` is omitted, all handlers of the given type are removed.
|
||||
* @param {string|symbol} type Type of event to unregister `handler` from
|
||||
* @param {Function} [handler] Handler function to remove
|
||||
* @memberOf mitt
|
||||
*/
|
||||
public off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>) {
|
||||
const handlers: Array<Handler<Events[Key]>> | undefined = this.all!.get(type);
|
||||
if (handlers) {
|
||||
if (handler) {
|
||||
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
|
||||
}
|
||||
else {
|
||||
this.all!.set(type, []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke all handlers for the given type.
|
||||
*
|
||||
* @param {string|symbol} type The event type to invoke
|
||||
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
|
||||
* @memberOf mitt
|
||||
*/
|
||||
emit<Key extends keyof Events>(type: Key, evt: Events[Key]) {
|
||||
let handlers = this.all!.get(type);
|
||||
if (handlers) {
|
||||
(handlers as EventHandlerList<Events[keyof Events]>)
|
||||
.slice()
|
||||
.map((handler) => {
|
||||
handler(evt!);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,795 @@
|
||||
import { LOGGER_FILTER, LOGGER_CONSOLE, LOGGER_STYLE } from "./Config";
|
||||
|
||||
/**
|
||||
* 调试输出样式
|
||||
*/
|
||||
class LogStyle {
|
||||
|
||||
/**
|
||||
* 日志文字颜色
|
||||
*/
|
||||
private color:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志背景颜色
|
||||
*/
|
||||
private backgroundColor:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字粗细
|
||||
*/
|
||||
private weight:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字大小
|
||||
*/
|
||||
private size:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字字体
|
||||
*/
|
||||
private family:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字圆角
|
||||
*/
|
||||
private borderRadius:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字边框
|
||||
*/
|
||||
private border:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字外边距
|
||||
*/
|
||||
private margin:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字内边距
|
||||
*/
|
||||
private padding:string | undefined;
|
||||
|
||||
/**
|
||||
* 设置颜色
|
||||
* @param color 日志文字颜色
|
||||
* @param backgroundColor 日志背景颜色
|
||||
*/
|
||||
public setColor(color?:string, backgroundColor?:string):LogStyle {
|
||||
this.color = color ?? this.color;
|
||||
this.backgroundColor = backgroundColor ?? this.backgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置边框
|
||||
* @param borderRadius 日志文字圆角
|
||||
* @param border 日志文字边框
|
||||
*/
|
||||
public setBorder(borderRadius?:string, border?:string):LogStyle {
|
||||
this.borderRadius = borderRadius ?? this.borderRadius;
|
||||
this.border = border ?? this.border;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文字
|
||||
* @param weight 日志文字粗细
|
||||
* @param family 日志文字字体
|
||||
*/
|
||||
public setFont(weight?:string, family?:string):LogStyle {
|
||||
this.weight = weight ?? this.weight;
|
||||
this.family = family ?? this.family;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文字大小
|
||||
* @param size 日志文字大小
|
||||
*/
|
||||
public setSize(size?:string):LogStyle {
|
||||
this.size = size ?? this.size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内边距外边距
|
||||
* @param padding 内边距
|
||||
* @param margin 外边距
|
||||
*/
|
||||
public setBlank(padding?:string, margin?:string):LogStyle {
|
||||
this.padding = padding ?? this.padding;
|
||||
this.margin = margin ?? this.margin;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符化转义样式
|
||||
*/
|
||||
public stringify():string {
|
||||
let stringArr:string[] = [];
|
||||
|
||||
this.color && stringArr.push(`color:${ this.color }`);
|
||||
this.backgroundColor && stringArr.push(`background-color:${ this.backgroundColor }`);
|
||||
this.weight && stringArr.push(`font-weight:${ this.weight }`);
|
||||
this.family && stringArr.push(`font-family:${ this.family }`);
|
||||
this.borderRadius && stringArr.push(`border-radius:${ this.borderRadius }`);
|
||||
this.border && stringArr.push(`border:${ this.border }`);
|
||||
this.size && stringArr.push(`font-size:${ this.size }`);
|
||||
this.padding && stringArr.push(`padding:${ this.padding }`);
|
||||
this.margin && stringArr.push(`margin:${ this.margin }`);
|
||||
|
||||
return stringArr.join(";");
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆一个新的 LogStyle
|
||||
*/
|
||||
public clone():LogStyle {
|
||||
return new LogStyle()
|
||||
.setColor(this.color, this.backgroundColor)
|
||||
.setBorder(this.borderRadius, this.border)
|
||||
.setFont(this.weight, this.family)
|
||||
.setBlank(this.padding, this.margin)
|
||||
.setSize(this.size)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志标签
|
||||
*/
|
||||
class LogLabel {
|
||||
|
||||
/**
|
||||
* 关键字
|
||||
* 用于标识这个类别
|
||||
*/
|
||||
public key:string;
|
||||
|
||||
/**
|
||||
* 文字样式
|
||||
*/
|
||||
public style:LogStyle;
|
||||
|
||||
/**
|
||||
* 是否受到过滤器影响
|
||||
*/
|
||||
public checked:boolean;
|
||||
|
||||
/**
|
||||
* 是否输出
|
||||
*/
|
||||
public display:boolean;
|
||||
|
||||
/**
|
||||
* 是否为附件标签
|
||||
* 例如回车、时间、代码位置
|
||||
*/
|
||||
public attach:boolean;
|
||||
|
||||
/**
|
||||
* @param key 关键字
|
||||
* @param style 文字样式
|
||||
*/
|
||||
constructor(key:string, style:LogStyle,
|
||||
checked?:boolean, display?:boolean, attach?:boolean) {
|
||||
this.key = key;
|
||||
this.style = style;
|
||||
this.checked = checked ?? true;
|
||||
this.display = display ?? true;
|
||||
this.attach = attach ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 Logger 输出使用的内容
|
||||
*/
|
||||
public getLoggerOutput():string {
|
||||
if(!this.display) return "";
|
||||
return `%c${ this.key }`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 Text 输出内容
|
||||
*/
|
||||
public getTextOutput():string {
|
||||
if(!this.display) return "";
|
||||
return `[${ this.key }]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 style 格式化
|
||||
*/
|
||||
public getStyleOutput():string {
|
||||
if(!this.display) return "";
|
||||
return this.style.stringify();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验
|
||||
*/
|
||||
public checking(src:RegExp | string):boolean {
|
||||
|
||||
let pass = false;
|
||||
|
||||
// 关闭校验
|
||||
if(!this.checked) return pass;
|
||||
|
||||
if(src instanceof RegExp) {
|
||||
pass = (src as RegExp).test(this.key)
|
||||
} else {
|
||||
pass = (src as string) === this.key;
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多重内容捆绑
|
||||
* 用于 log 输出
|
||||
*/
|
||||
class MultipleLogContent<T extends Array<any>> {
|
||||
|
||||
/**
|
||||
* 输出内容
|
||||
*/
|
||||
private readonly content:T;
|
||||
|
||||
/**
|
||||
* @param content 输出内容
|
||||
*/
|
||||
public constructor(...content:T) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
*/
|
||||
public getContent():T {
|
||||
return this.content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日志输出
|
||||
*/
|
||||
class Logger {
|
||||
|
||||
/**
|
||||
* 标签过滤
|
||||
*/
|
||||
public static filterLog(filter:Array<RegExp | string>, labels:LogLabel[]):boolean {
|
||||
|
||||
let passNum:number = 0;
|
||||
|
||||
for(let i = 0; i < filter.length; i++) {
|
||||
|
||||
let pass:boolean = false;
|
||||
for(let j = 0; j < labels.length; j++) {
|
||||
|
||||
pass = labels[j].checking(filter[i]);
|
||||
if(pass) break;
|
||||
}
|
||||
|
||||
if(pass) passNum ++;
|
||||
}
|
||||
|
||||
return passNum === filter.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否应该输出
|
||||
* @param labels 使用标签
|
||||
*/
|
||||
public static testLog(...labels:LogLabel[]):boolean {
|
||||
|
||||
if(!LOGGER_CONSOLE) return false;
|
||||
|
||||
let isLogging = false;
|
||||
for(let i = 0; i < LOGGER_FILTER.length; i++) {
|
||||
|
||||
// 判断是否进行输出
|
||||
isLogging = Logger.filterLog(LOGGER_FILTER[i], labels);
|
||||
|
||||
if(isLogging) break;
|
||||
}
|
||||
|
||||
return isLogging;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集计算样式
|
||||
* @param labels 使用标签
|
||||
*/
|
||||
public static calcStyle(...labels:LogLabel[]):[string[], string[]] {
|
||||
|
||||
let consoleLabels:string[] = [];
|
||||
let consoleStyles:string[] = [];
|
||||
|
||||
// 放置标签
|
||||
for(let i = 0; i < labels.length; i++) {
|
||||
consoleLabels.push(labels[i].getLoggerOutput());
|
||||
|
||||
if (i !== ( labels.length - 1))
|
||||
consoleLabels.push("%c ");
|
||||
|
||||
consoleStyles.push(labels[i].getStyleOutput());
|
||||
|
||||
if (i !== ( labels.length - 1))
|
||||
consoleStyles.push("");
|
||||
}
|
||||
|
||||
return [consoleLabels, consoleStyles];
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集计算标签没有样式
|
||||
* @param labels 标签
|
||||
*/
|
||||
public static calcLabel(...labels:LogLabel[]):string[] {
|
||||
|
||||
let consoleLabels:string[] = [];
|
||||
|
||||
// 放置标签
|
||||
for(let i = 0; i < labels.length; i++) {
|
||||
consoleLabels.push(labels[i].getTextOutput());
|
||||
}
|
||||
|
||||
return consoleLabels
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础调试输出
|
||||
* 其他的 Log 函数都是基于此封装
|
||||
* @param content 输出内容
|
||||
* @param label 使用标签
|
||||
* @param attachLabel 附加标签
|
||||
*/
|
||||
public static logBase<T extends Array<any>>
|
||||
(content:MultipleLogContent<T>, labels:LogLabel[], attachLabel:LogLabel[] = []):T {
|
||||
|
||||
// TODO: 这里可以添加一些钩子作为中间件处理日志输出
|
||||
|
||||
// 测试是否输出内容
|
||||
if(!Logger.testLog(...labels, ...attachLabel, StackLogLabel.filterUrlLabel))
|
||||
return content.getContent();
|
||||
|
||||
// 过滤出需要渲染的 Labels
|
||||
let labelsNeedRender:LogLabel[] = [...labels, ...attachLabel].filter((label:LogLabel)=>{
|
||||
return true
|
||||
});
|
||||
|
||||
// 使用样式输出
|
||||
if(LOGGER_STYLE) {
|
||||
|
||||
// 计算收集样式
|
||||
let [consoleLabels, consoleStyles]= Logger.calcStyle(...labelsNeedRender);
|
||||
|
||||
// 调试输出
|
||||
console.log(consoleLabels.join(""), ...consoleStyles, ...content.getContent());
|
||||
|
||||
} else {
|
||||
|
||||
// 计算收集标签
|
||||
let consoleLabels= Logger.calcLabel(...labelsNeedRender);
|
||||
|
||||
// 输出
|
||||
console.log(consoleLabels.join(" "), ...content.getContent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
return content.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试输出
|
||||
* @param content 输出内容
|
||||
* @param label 使用标签
|
||||
*/
|
||||
public static log<T>(content:T, ...labels:LogLabel[]):T {
|
||||
return Logger.logBase<Array<T>>(
|
||||
new MultipleLogContent<Array<T>>(content), labels,
|
||||
[StackLogLabel.fileNameLabel]
|
||||
)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数 Logger.log 的别名
|
||||
*/
|
||||
public static l:typeof Logger.log = Logger.log;
|
||||
|
||||
/**
|
||||
* 多重调试输出
|
||||
* @param labels 输出内容
|
||||
* @param content 使用标签
|
||||
*/
|
||||
public static logMultiple<T extends Array<any>>(labels:LogLabel[], ...content:T):T {
|
||||
return Logger.logBase<T>(
|
||||
new MultipleLogContent<T>(...content), labels,
|
||||
[StackLogLabel.fileNameLabel]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数 Logger.logMultiple 的别名
|
||||
*/
|
||||
public static m:typeof Logger.logMultiple = Logger.logMultiple;
|
||||
|
||||
/**
|
||||
* 在下一行调试输出
|
||||
* @param content 输出内容
|
||||
* @param label 使用标签
|
||||
*/
|
||||
public static logLine<T>(content:T, ...labels:LogLabel[]):T {
|
||||
return Logger.logBase<Array<T>>(
|
||||
new MultipleLogContent<Array<T>>(content), labels,
|
||||
[StackLogLabel.fileNameLabel, StackLogLabel.blankLabel]
|
||||
)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数 Logger.logLine 的别名
|
||||
*/
|
||||
public static ll:typeof Logger.logLine = Logger.logLine;
|
||||
|
||||
/**
|
||||
* 在下一行多重调试输出
|
||||
* @param labels 输出内容
|
||||
* @param content 使用标签
|
||||
*/
|
||||
public static logLineMultiple<T extends Array<any>>(labels:LogLabel[], ...content:T):T {
|
||||
return Logger.logBase<T>(
|
||||
new MultipleLogContent<T>(...content), labels,
|
||||
[StackLogLabel.fileNameLabel, StackLogLabel.blankLabel]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数 Logger.logLineMultiple 的别名
|
||||
*/
|
||||
public static lm:typeof Logger.logLineMultiple = Logger.logLineMultiple;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 栈信息
|
||||
*/
|
||||
class StackInfo {
|
||||
|
||||
/**
|
||||
* 函数名
|
||||
*/
|
||||
public functionName:string | undefined;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
public fileName:string | undefined;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
public url:string | undefined;
|
||||
|
||||
/**
|
||||
* 文件名和行号
|
||||
*/
|
||||
public fileNameLine: string | undefined;
|
||||
|
||||
/**
|
||||
* 设置信息
|
||||
* @param functionName 函数名
|
||||
* @param fileName 文件名
|
||||
* @param url 文件路径
|
||||
*/
|
||||
public setInfo(functionName:string, fileNameLine:string, url:string):StackInfo {
|
||||
this.functionName = functionName;
|
||||
this.fileNameLine = fileNameLine;
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算文件名
|
||||
*/
|
||||
public calcFileName():string | undefined {
|
||||
|
||||
let replaceToTs = this.fileNameLine?.replace(".js", ".ts");
|
||||
let matched = replaceToTs?.match(/^(.+\.(js|ts)):\d+:\d+$/);
|
||||
|
||||
return matched ? matched[1] : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算路径名
|
||||
*/
|
||||
public calcPathName():string | undefined {
|
||||
|
||||
let replaceToTs = this.url?.replace(".js", ".ts");
|
||||
let matched = replaceToTs?.match(/^https?:\/\/(\d+\.){3}\d+:\d+\/(.+):\d+:\d+$/);
|
||||
|
||||
return matched ? matched[2] : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取函数调用栈列表
|
||||
*/
|
||||
public static getCallStack():StackInfo[] {
|
||||
|
||||
// 获取堆栈信息
|
||||
let stack:string | undefined = new Error().stack;
|
||||
|
||||
if (stack === void 0) return [];
|
||||
|
||||
// 去除 Error
|
||||
stack = stack.replace(/^(Error)\s/, "");
|
||||
|
||||
// 获取堆栈信息
|
||||
let stackList:string[] = stack.split(/\n/);
|
||||
|
||||
let callStack:StackInfo[] = [];
|
||||
|
||||
for(let i = 0; i < stackList.length; i++) {
|
||||
|
||||
let matcher = stackList[i].match(/^\s+at\s+(.+)\s(\(.+\))/);
|
||||
if (matcher === null || matcher.length < 3) continue;
|
||||
|
||||
let fileName = matcher[2].match(/.+\/(.+\..+:\d+:\d+)\)/);
|
||||
if (fileName === null || matcher.length < 2) continue;
|
||||
|
||||
callStack.push(new StackInfo().setInfo(
|
||||
matcher[1], fileName[1], matcher[2]?.replace(/(\(|\))/g, "")
|
||||
))
|
||||
}
|
||||
|
||||
// console.log(callStack);
|
||||
|
||||
return callStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 排除的
|
||||
*/
|
||||
public static readonly excludeFile:RegExp = /^.*(\\|\/)core(\\|\/)(.*Log.*).js:\d+:\d+/;
|
||||
|
||||
/**
|
||||
* 获取第一个调用栈
|
||||
*/
|
||||
public static getFirstStack():StackInfo | undefined {
|
||||
|
||||
let callStack = this.getCallStack();
|
||||
|
||||
for(let i = 0; i < callStack.length; i++) {
|
||||
|
||||
if(!callStack[i].url) continue;
|
||||
|
||||
if(!StackInfo.excludeFile.test(callStack[i].url ?? "")) {
|
||||
return callStack[i];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部预定义的 LogLabel
|
||||
*/
|
||||
class StackLogLabel {
|
||||
|
||||
/**
|
||||
* 堆栈路径样式
|
||||
*/
|
||||
public static readonly normalStyle:LogStyle = new LogStyle()
|
||||
.setColor("#979797").setBorder("4px", "1px solid #979797").setBlank("0 5px");
|
||||
|
||||
/**
|
||||
* 一个回车
|
||||
*/
|
||||
public static readonly blankLabel = new LogLabel("\n\r",
|
||||
new LogStyle(), false, true, true);
|
||||
|
||||
/**
|
||||
* 包含文件名和行号的 label
|
||||
*/
|
||||
public static get fileNameLabel():LogLabel {
|
||||
|
||||
// 获得调用堆栈
|
||||
let stack = StackInfo.getFirstStack();
|
||||
|
||||
return new LogLabel(stack?.calcFileName() ?? "Unknown file name",
|
||||
StackLogLabel.normalStyle, false, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 包含 URL 链接的 label
|
||||
*/
|
||||
public static get urlLabel():LogLabel {
|
||||
|
||||
// 获得调用堆栈
|
||||
let stack = StackInfo.getFirstStack();
|
||||
|
||||
return new LogLabel(stack?.calcPathName() ?? "Unknown url",
|
||||
StackLogLabel.normalStyle, false, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅仅用来 filter 的 URL 链接的 label
|
||||
*/
|
||||
public static get filterUrlLabel():LogLabel {
|
||||
|
||||
// 获得调用堆栈
|
||||
let stack = StackInfo.getFirstStack();
|
||||
|
||||
return new LogLabel(stack?.calcPathName() ?? "Unknown url",
|
||||
StackLogLabel.normalStyle, true, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成圆角颜色标签样式
|
||||
*/
|
||||
const normalLevelStyleGen = (color:string):LogStyle => {
|
||||
return new LogStyle().setBorder("4px", `1px solid ${color}`)
|
||||
.setColor(color).setBlank("0 5px");
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试等级标签
|
||||
*/
|
||||
class LevelLogLabel {
|
||||
|
||||
/**
|
||||
* 致命
|
||||
*/
|
||||
static readonly FatalLabel = new LogLabel(
|
||||
"FATAL", normalLevelStyleGen("#FF00CC")
|
||||
);
|
||||
|
||||
/**
|
||||
* 错误
|
||||
*/
|
||||
static readonly ErrorLabel = new LogLabel(
|
||||
"ERROR", normalLevelStyleGen("#FF0000")
|
||||
);
|
||||
|
||||
/**
|
||||
* 警告
|
||||
*/
|
||||
static readonly WarnLabel = new LogLabel(
|
||||
"WARN", normalLevelStyleGen("#FF9900")
|
||||
);
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
static readonly InfoLabel = new LogLabel(
|
||||
"INFO", normalLevelStyleGen("#99FF00")
|
||||
);
|
||||
|
||||
/**
|
||||
* 调试
|
||||
*/
|
||||
static readonly DebugLabel = new LogLabel(
|
||||
"DEBUG", normalLevelStyleGen("#00FF99")
|
||||
);
|
||||
|
||||
/**
|
||||
* 追踪
|
||||
*/
|
||||
static readonly TraceLabel = new LogLabel(
|
||||
"TRACE", normalLevelStyleGen("#00CCFF")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成圆角颜色标签样式
|
||||
*/
|
||||
const normalLifeStyleGen = (r:number, g:number, b:number):LogStyle => {
|
||||
return new LogStyle().setBorder("4px", `1px solid rgb(${ r }, ${ g }, ${ b })`)
|
||||
.setColor(`rgb(${ r }, ${ g }, ${ b })`, `rgba(${ r }, ${ g }, ${ b }, .1)`)
|
||||
.setBlank("0 5px");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生命周期标签
|
||||
*/
|
||||
class LifeCycleLogLabel {
|
||||
|
||||
/**
|
||||
* 小程序加载时
|
||||
*/
|
||||
static readonly OnLaunchLabel = new LogLabel(
|
||||
"onLaunch", normalLifeStyleGen(160, 32, 240)
|
||||
);
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
static readonly OnLoadLabel = new LogLabel(
|
||||
"onLoad", normalLifeStyleGen(255, 140, 105)
|
||||
);
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
static readonly OnReadyLabel = new LogLabel(
|
||||
"onReady", normalLifeStyleGen(255, 127, 36)
|
||||
);
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
static readonly OnShowLabel = new LogLabel(
|
||||
"onShow", normalLifeStyleGen(255, 215, 0)
|
||||
)
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
static readonly OnHideLabel = new LogLabel(
|
||||
"onHide", normalLifeStyleGen(173, 255, 47)
|
||||
);
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
static readonly OnUnloadLabel = new LogLabel(
|
||||
"onUnload", normalLifeStyleGen(127, 255, 212)
|
||||
);
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
static readonly OnPullDownRefreshLabel = new LogLabel(
|
||||
"onPullDownRefresh", normalLifeStyleGen(0, 191, 255)
|
||||
);
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
static readonly OnReachBottomLabel = new LogLabel(
|
||||
"onReachBottom", normalLifeStyleGen(84, 255, 159)
|
||||
);
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
static readonly OnShareAppMessageLabel = new LogLabel(
|
||||
"onShareAppMessage", normalLifeStyleGen(147, 112, 219)
|
||||
);
|
||||
}
|
||||
|
||||
class StatusLabel {
|
||||
|
||||
/**
|
||||
* 等待
|
||||
*/
|
||||
static readonly Pending = new LogLabel(
|
||||
"◉", new LogStyle().setBlank("0 2px").setBorder("1000px", "1px solid lightblue").setColor("lightblue")
|
||||
);
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
static readonly Success = new LogLabel(
|
||||
"√", new LogStyle().setBlank("0 4px").setBorder("1000px", "1px solid lightgreen").setColor("lightgreen")
|
||||
);
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
static readonly Failed = new LogLabel(
|
||||
"x", new LogStyle().setBlank("0 4px").setBorder("1000px", "1px solid red").setColor("red")
|
||||
);
|
||||
}
|
||||
|
||||
const NormalStyle = StackLogLabel.normalStyle;
|
||||
|
||||
export default Logger;
|
||||
export {
|
||||
Logger, LogLabel, LevelLogLabel, StackLogLabel, LifeCycleLogLabel, LogStyle,
|
||||
StackInfo, StatusLabel, NormalStyle, normalLifeStyleGen as colorRadio
|
||||
};
|
||||
@@ -0,0 +1,496 @@
|
||||
import { Emitter } from "./Emitter";
|
||||
import { Logger, LogLabel, colorRadio, LevelLogLabel } from "./Logger";
|
||||
|
||||
/**
|
||||
* 自定义对象类型
|
||||
*/
|
||||
type IAnyTypeObject<T = any> = {
|
||||
[x:string]: T;
|
||||
};
|
||||
|
||||
// 微信 Data 类型
|
||||
type Data<D> = WechatMiniprogram.Page.Data<D>;
|
||||
|
||||
// 微信生命周期类型
|
||||
type ILifetime = WechatMiniprogram.Page.ILifetime;
|
||||
|
||||
// 继承的方法
|
||||
type InstanceMethods<D> = WechatMiniprogram.Page.InstanceMethods<D>;
|
||||
|
||||
// 继承的属性
|
||||
type InstanceProperties = WechatMiniprogram.Page.InstanceProperties;
|
||||
|
||||
/**
|
||||
* 定义微信微信上下文类型
|
||||
*
|
||||
* @template TD data 结构类型
|
||||
* @template TC 用户 MinIn 类型
|
||||
*
|
||||
* Partial<ILifetime> 可选的微信生命周期
|
||||
* Partial<Data<TD>> 可选的 data 结构
|
||||
* InstanceMethods<TD> 必选的微信继承方法
|
||||
* InstanceProperties 必选的微信继承属性
|
||||
*/
|
||||
type WXContext<TD, TC> = Partial<ILifetime> & Partial<Data<TD>>
|
||||
& InstanceMethods<TD> & InstanceProperties & TC;
|
||||
|
||||
/**
|
||||
* 任意的微信上下文
|
||||
* 当我们不关心具体是哪个上下文时
|
||||
* 使用这个类型
|
||||
*/
|
||||
type AnyWXContext = WXContext<IAnyTypeObject, IAnyTypeObject>;
|
||||
|
||||
/**
|
||||
* 依赖关系图谱
|
||||
* 注意: 这是一个递给类型
|
||||
* @template M 限制了所有依赖必须使用同一个 manager
|
||||
*/
|
||||
type Depends<M extends Manager<AnyWXContext>> = {
|
||||
[x:string]: Modular<M, Depends<M>>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 微信继承的函数
|
||||
*/
|
||||
class WXInstanceMethods<
|
||||
E extends IAnyTypeObject = IAnyTypeObject,
|
||||
W extends AnyWXContext = AnyWXContext
|
||||
>
|
||||
extends Emitter<E>
|
||||
implements InstanceMethods<W["data"]> {
|
||||
|
||||
public superContext: W;
|
||||
|
||||
public constructor(context: W) {
|
||||
super();
|
||||
this.superContext = context;
|
||||
}
|
||||
|
||||
public setData(data: Partial<W["data"]> & WechatMiniprogram.IAnyObject, callback?: () => void): void {
|
||||
return this.superContext.setData(data, callback);
|
||||
}
|
||||
|
||||
public hasBehavior(behavior: string): void {
|
||||
return this.superContext.hasBehavior(behavior);
|
||||
}
|
||||
|
||||
public triggerEvent<DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption): void {
|
||||
return this.superContext.triggerEvent(name, detail, options)
|
||||
}
|
||||
|
||||
public createSelectorQuery(): WechatMiniprogram.SelectorQuery {
|
||||
return this.superContext.createSelectorQuery();
|
||||
}
|
||||
|
||||
public createIntersectionObserver(options: WechatMiniprogram.CreateIntersectionObserverOption): WechatMiniprogram.IntersectionObserver {
|
||||
return this.superContext.createIntersectionObserver(options);
|
||||
}
|
||||
|
||||
public selectComponent(selector: string): WechatMiniprogram.Component.TrivialInstance {
|
||||
return this.superContext.selectComponent(selector);
|
||||
}
|
||||
|
||||
public selectAllComponents(selector: string): WechatMiniprogram.Component.TrivialInstance[] {
|
||||
return this.superContext.selectAllComponents(selector);
|
||||
}
|
||||
|
||||
public selectOwnerComponent(): WechatMiniprogram.Component.TrivialInstance {
|
||||
return this.superContext.selectOwnerComponent();
|
||||
}
|
||||
|
||||
public getRelationNodes(relationKey: string): WechatMiniprogram.Component.TrivialInstance[] {
|
||||
return this.superContext.getRelationNodes(relationKey);
|
||||
}
|
||||
|
||||
public groupSetData(callback?: () => void): void {
|
||||
return this.superContext.groupSetData(callback);
|
||||
}
|
||||
|
||||
public getTabBar(): WechatMiniprogram.Component.TrivialInstance {
|
||||
return this.superContext.getTabBar();
|
||||
}
|
||||
|
||||
public getPageId(): string {
|
||||
return this.superContext.getPageId();
|
||||
}
|
||||
|
||||
public animate(selector: string, keyFrames: WechatMiniprogram.Component.KeyFrame[], duration: number, callback?: () => void): void;
|
||||
public animate(selector: string, keyFrames: WechatMiniprogram.Component.ScrollTimelineKeyframe[], duration: number,
|
||||
scrollTimeline: WechatMiniprogram.Component.ScrollTimelineOption): void;
|
||||
public animate(selector: any, keyFrames: any, duration: any, scrollTimeline?: any): void {
|
||||
return this.superContext.animate(selector, keyFrames, duration, scrollTimeline);
|
||||
}
|
||||
|
||||
public clearAnimation(selector: string, callback: () => void): void;
|
||||
public clearAnimation(selector: string, options?: WechatMiniprogram.Component.ClearAnimationOptions, callback?: () => void): void;
|
||||
public clearAnimation(selector: any, options?: any, callback?: any): void {
|
||||
return this.superContext.clearAnimation(selector, options, callback);
|
||||
}
|
||||
|
||||
public getOpenerEventChannel(): WechatMiniprogram.EventChannel {
|
||||
return this.superContext.getOpenerEventChannel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信继承的属性
|
||||
*/
|
||||
class WXInstanceProperties<
|
||||
E extends IAnyTypeObject = IAnyTypeObject,
|
||||
W extends AnyWXContext = AnyWXContext
|
||||
>
|
||||
extends WXInstanceMethods<E, W>
|
||||
implements InstanceProperties {
|
||||
|
||||
public override superContext: W;
|
||||
|
||||
constructor(context: W) {
|
||||
super(context);
|
||||
this.superContext = context;
|
||||
}
|
||||
|
||||
public get is(): string { return this.superContext.is };
|
||||
|
||||
public get route(): string { return this.superContext.route };
|
||||
|
||||
public get options(): Record<string, string | undefined> { return this.superContext.options };
|
||||
}
|
||||
|
||||
class WXILifetime<
|
||||
E extends IAnyTypeObject = IAnyTypeObject,
|
||||
W extends AnyWXContext = AnyWXContext
|
||||
>
|
||||
extends WXInstanceProperties<E, W>
|
||||
implements ILifetime {
|
||||
|
||||
public onLoad(query: Record<string, string | undefined>): void | Promise<void> {};
|
||||
|
||||
public onShow(): void | Promise<void> {};
|
||||
|
||||
public onReady(): void | Promise<void> {};
|
||||
|
||||
public onHide(): void | Promise<void> {};
|
||||
|
||||
public onUnload(): void | Promise<void> {};
|
||||
|
||||
public onPullDownRefresh(): void | Promise<void> {};
|
||||
|
||||
public onReachBottom(): void | Promise<void> {};
|
||||
|
||||
public onShareAppMessage(options: WechatMiniprogram.Page.IShareAppMessageOption): void | WechatMiniprogram.Page.ICustomShareContent {};
|
||||
|
||||
public onShareTimeline(): void | WechatMiniprogram.Page.ICustomTimelineContent {};
|
||||
|
||||
public onPageScroll(options: WechatMiniprogram.Page.IPageScrollOption): void | Promise<void> {};
|
||||
|
||||
public onTabItemTap(options: WechatMiniprogram.Page.ITabItemTapOption): void | Promise<void> {};
|
||||
|
||||
public onResize(options: WechatMiniprogram.Page.IResizeOption): void | Promise<void> {};
|
||||
|
||||
public onAddToFavorites(options: WechatMiniprogram.Page.IAddToFavoritesOption): WechatMiniprogram.Page.IAddToFavoritesContent {
|
||||
return {};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面模组
|
||||
* @template M 所属 Manager
|
||||
* @template DEP 模组依赖
|
||||
* @template E 模组事件
|
||||
* @template TD 模组 Data 类型
|
||||
*/
|
||||
class Modular<
|
||||
M extends Manager<AnyWXContext> = Manager<AnyWXContext>,
|
||||
DEP extends Depends<M> = Depends<M>,
|
||||
E extends IAnyTypeObject = IAnyTypeObject,
|
||||
TD extends IAnyTypeObject = IAnyTypeObject
|
||||
>
|
||||
extends WXILifetime<E, M["context"]>
|
||||
implements WXContext<TD, IAnyTypeObject> {
|
||||
|
||||
// [x:string]: any;
|
||||
|
||||
/**
|
||||
* 保存页面上下文
|
||||
*/
|
||||
private manager:M;
|
||||
|
||||
/**
|
||||
* 映射 Manager 上下文
|
||||
*/
|
||||
private get context():M["context"] {
|
||||
return this.manager.context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模组依赖
|
||||
*/
|
||||
protected depends?:DEP
|
||||
|
||||
/**
|
||||
* 模组数据
|
||||
*/
|
||||
public data?:TD;
|
||||
|
||||
/**
|
||||
* 模组使用的函数列表
|
||||
*/
|
||||
public functionList:Set<string>;
|
||||
|
||||
/**
|
||||
* 模组使用的参数列表
|
||||
*/
|
||||
public paramList:Set<string>;
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
public nameSpace:string;
|
||||
|
||||
/**
|
||||
* 一旦被类被构造,整个页面的全部申明周期将
|
||||
* 由该类实例控制,此后请勿修改任何生命周期函数
|
||||
* @param manager 页面上下文
|
||||
* @param nameSpace 模组命名空间
|
||||
* @param depend 模组依赖
|
||||
*/
|
||||
public constructor(manager:M, nameSpace:string, depend?: DEP) {
|
||||
|
||||
super(manager.context);
|
||||
|
||||
// 保存微信上下文
|
||||
this.manager = manager;
|
||||
|
||||
// 保存模块依赖
|
||||
this.depends = depend;
|
||||
|
||||
// 初始化内部属性
|
||||
this.functionList = new Set<string>();
|
||||
this.paramList = new Set<string>();
|
||||
this.nameSpace = nameSpace;
|
||||
}
|
||||
|
||||
public override setData(data:Partial<TD>, callback?: () => void):void {
|
||||
|
||||
if(this.data === void 0) {
|
||||
this.data = {} as TD;
|
||||
}
|
||||
|
||||
let reportData:IAnyTypeObject = {};
|
||||
|
||||
for(let key in data) {
|
||||
(this.data as IAnyTypeObject)[key] = data[key];
|
||||
reportData[`${ this.nameSpace }$${ key }`] = data[key];
|
||||
this.paramList.add(key);
|
||||
}
|
||||
|
||||
return this.context.setData(reportData, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向上层上下文传递函数
|
||||
* @param fn 传递的函数
|
||||
* @param name 函数名字
|
||||
*/
|
||||
public setFunc(fn:Function, name:string):void {
|
||||
|
||||
this.functionList.add(name);
|
||||
(this.context as IAnyTypeObject)
|
||||
[`${ this.nameSpace }$${ name }`] = fn.bind(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面控件
|
||||
* 用于管理页面的所有模组
|
||||
*/
|
||||
class Manager<WXC extends AnyWXContext = AnyWXContext> {
|
||||
|
||||
/**
|
||||
* 微信生命周期
|
||||
*/
|
||||
static readonly WxLifeCycle:(keyof ILifetime)[] = [
|
||||
"onShow", "onReady", "onHide", "onUnload", "onPullDownRefresh", "onReachBottom",
|
||||
"onShareAppMessage", "onShareTimeline","onAddToFavorites","onPageScroll", "onResize", "onTabItemTap"
|
||||
];
|
||||
|
||||
/**
|
||||
* 保存页面上下文
|
||||
*/
|
||||
public context:WXC;
|
||||
|
||||
/**
|
||||
* 一旦被类被构造,整个页面的全部申明周期将
|
||||
* 由该类实例控制,此后请勿修改任何生命周期函数
|
||||
*/
|
||||
public constructor(context:WXC) {
|
||||
|
||||
// 保存微信上下文
|
||||
this.context = context;
|
||||
|
||||
// 初始化模组列表
|
||||
this.modules = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 模组列表
|
||||
*/
|
||||
public modules:Modular[];
|
||||
|
||||
/**
|
||||
* 添加一个模块
|
||||
* @param mode 模块类
|
||||
* @param nameSpace 命名空间
|
||||
* @param depend 模块依赖
|
||||
* @returns 模块实例
|
||||
*/
|
||||
public addModule<DEP extends Depends<this>, M extends Modular<this, DEP>> (
|
||||
mode: new (manager:this, nameSpace:string, depend?:DEP) => M,
|
||||
nameSpace:string, depend?:DEP
|
||||
):M {
|
||||
let mod = new mode(this, nameSpace, depend);
|
||||
this.modules.push(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建指定生命周期的钩子
|
||||
* @param key 生命周期键值
|
||||
*/
|
||||
public creatHooks<Key extends keyof ILifetime>(key: Key): ILifetime[Key] {
|
||||
let hook = (async (...arg: any[]) => {
|
||||
|
||||
let hooks:Promise<any>[] = [];
|
||||
|
||||
for(let i = 0; i < this.modules.length; i++) {
|
||||
|
||||
let fn:Function = this.modules[i][key];
|
||||
|
||||
if(fn === void 0) continue;
|
||||
let res: Promise<any> | any = fn.apply(this.modules[i], arg);
|
||||
|
||||
if (res instanceof Promise) {
|
||||
hooks.push(res);
|
||||
} else {
|
||||
hooks.push(Promise.resolve(res));
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
key === "onShareAppMessage" ||
|
||||
key === "onShareTimeline" ||
|
||||
key === "onAddToFavorites"
|
||||
) {
|
||||
|
||||
// 如果返回值有特殊含义在处理时进行 MinIn
|
||||
return Promise.all(hooks).then((res) => {
|
||||
|
||||
let simple:IAnyTypeObject = {};
|
||||
|
||||
for(let i = 0; i < res.length; i++) {
|
||||
simple = Object.assign({}, simple, res);
|
||||
}
|
||||
|
||||
return Promise.resolve(simple);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return Promise.all(hooks);
|
||||
});
|
||||
|
||||
// TODO: 此处为,关键位置,容易出错,请再次检查
|
||||
return (hook as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建全部生命周期钩子
|
||||
*/
|
||||
public creatAllHooks() {
|
||||
for(let i = 0; i < Manager.WxLifeCycle.length; i++) {
|
||||
(this.context as IAnyTypeObject)[Manager.WxLifeCycle[i]] =
|
||||
this.creatHooks(Manager.WxLifeCycle[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载全部的模块
|
||||
* @param query onLoad 接收的参数
|
||||
*/
|
||||
public loadAllModule(query:Record<string, string | undefined>) {
|
||||
|
||||
// 创建全部钩子
|
||||
this.creatAllHooks();
|
||||
|
||||
// 加载全部模组数据
|
||||
for(let i = 0; i < this.modules.length; i++) {
|
||||
|
||||
if(this.modules[i].data)
|
||||
for(let key in this.modules[i].data) {
|
||||
|
||||
if(this.context.data === void 0) this.context.data = {};
|
||||
|
||||
if(this.modules[i].data !== void 0) {
|
||||
this.context.data[`${ this.modules[i].nameSpace }$${ key }`] =
|
||||
( this.modules[i].data as IAnyTypeObject )[key];
|
||||
this.modules[i].paramList.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将全部数据发布到视图层
|
||||
if(this.context.data !== void 0)
|
||||
this.context.setData(this.context.data);
|
||||
|
||||
// 调用全部模块的 onLoad 周期
|
||||
let res = this.creatHooks("onLoad")(query);
|
||||
|
||||
// 打印每个模块的键值对使用情况
|
||||
for(let i = 0; i < this.modules.length; i++) {
|
||||
let data:string[] = [];
|
||||
let func:string[] = [];
|
||||
|
||||
for(let key of this.modules[i].paramList) {
|
||||
data.push(`[${ key }]`);
|
||||
}
|
||||
|
||||
for(let key of this.modules[i].functionList) {
|
||||
func.push(`[${ key }]`);
|
||||
}
|
||||
|
||||
let log:string = `模块 [${ this.modules[i].nameSpace }] 完成绑定...\n`;
|
||||
if(data.length > 0) log += `Using Props: ${ data.join(", ") }\n`;
|
||||
if(func.length > 0) log += `Using Function: ${ func.join(", ") }\n`;
|
||||
|
||||
Logger.log(log, LevelLogLabel.InfoLabel, Manager.AddModuleLabel);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块被添加时的标签
|
||||
*/
|
||||
public static readonly AddModuleLabel = new LogLabel(
|
||||
"addModule",
|
||||
colorRadio(54, 0, 255)
|
||||
)
|
||||
|
||||
/**
|
||||
* 加载 Manager 控件
|
||||
* @param fn 约束后调用的函数用来添加模块
|
||||
*/
|
||||
public static Page(fn:(manager:Manager<AnyWXContext>) => void) {
|
||||
Page({
|
||||
async onLoad(query) {
|
||||
let manager = new Manager(this);
|
||||
fn(manager);
|
||||
manager.loadAllModule(query);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Manager, Modular, AnyWXContext, WXContext, ILifetime}
|
||||
@@ -0,0 +1,270 @@
|
||||
import { Logger, LogLabel, LevelLogLabel, colorRadio } from "./Logger";
|
||||
|
||||
interface IAppStorageParam {
|
||||
|
||||
/**
|
||||
* storage 缓存
|
||||
*/
|
||||
storage: Map<string, Storage<IStorageData>>
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
enum StorageState {
|
||||
|
||||
/**
|
||||
* 有 waiter 存在的工作状态
|
||||
*/
|
||||
WORK = 1,
|
||||
|
||||
/**
|
||||
* 无 waiter 存在的完成状态
|
||||
*/
|
||||
DONE = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务等待列表
|
||||
*/
|
||||
class Waiter {
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
public get state():StorageState {
|
||||
if(this.waiterList.length <= 0) {
|
||||
return StorageState.DONE;
|
||||
} else {
|
||||
return StorageState.WORK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数列表
|
||||
*/
|
||||
private waiterList:Function[] = [];
|
||||
|
||||
/**
|
||||
* 添加等待者
|
||||
* @param fn 等待者
|
||||
*/
|
||||
public addWaiter(fn:Function) {
|
||||
this.waiterList.push(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成
|
||||
* 清空 waiterList
|
||||
* 并返回合并的 waiterList
|
||||
*/
|
||||
public done():Function {
|
||||
|
||||
// 复制 waiterList 生成闭包
|
||||
let fnList = this.waiterList.concat([]);
|
||||
|
||||
let runAllWaiter = () => {
|
||||
for(let i = 0; i < fnList.length; i++) {
|
||||
fnList[i]();
|
||||
}
|
||||
}
|
||||
|
||||
this.waiterList = [];
|
||||
return runAllWaiter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储数据类型
|
||||
*/
|
||||
type IStorageData = {
|
||||
[x:string]:any
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储库
|
||||
* @template T 数据类型
|
||||
*
|
||||
* 特点:
|
||||
* 1. 该类封装了 wxStorage 操作
|
||||
* 2. 全异步获取无阻塞
|
||||
* 3. 使用数据缓缓冲区,优化高频存取
|
||||
* 4. 如果全局范围内已存在莫键值 storage 的实例
|
||||
* 则此实例将链接到已存在实例
|
||||
*/
|
||||
class Storage<T extends IStorageData> {
|
||||
|
||||
/**
|
||||
* Logger 使用的标签
|
||||
*/
|
||||
public StorageLogLabel:LogLabel;
|
||||
|
||||
/**
|
||||
* 数据唯一索引
|
||||
*/
|
||||
public key:string;
|
||||
|
||||
/**
|
||||
* 数据键值的默认数据类型
|
||||
*/
|
||||
private readonly defaultData:T;
|
||||
|
||||
/**
|
||||
* 缓存数据
|
||||
*/
|
||||
private _cache: T = {} as T;
|
||||
private set cache(data: T) {
|
||||
if (this.cacheStorage) {
|
||||
for (const key in data) {
|
||||
this.cacheStorage.cache[key] = data[key];
|
||||
}
|
||||
} else {
|
||||
for (const key in data) {
|
||||
this._cache[key] = data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
private get cache():T {
|
||||
if (this.cacheStorage) return this.cacheStorage.cache;
|
||||
else return this._cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* cache 到 storage 等待列表
|
||||
*/
|
||||
private saveWaiter:Waiter = new Waiter();
|
||||
|
||||
/**
|
||||
* 缓存对象
|
||||
*/
|
||||
private cacheStorage:Storage<T> | undefined;
|
||||
|
||||
/**
|
||||
* 将数据从 cache 同步到 storage
|
||||
*/
|
||||
public async save():Promise<void> {
|
||||
|
||||
// 如果存在链接的实例
|
||||
if (this.cacheStorage) return this.cacheStorage.save();
|
||||
|
||||
// 如果没有开始存储
|
||||
// 发起一次异步读取
|
||||
if(this.saveWaiter.state === StorageState.DONE)
|
||||
setTimeout(() => {
|
||||
|
||||
// 获取函数绑定列表
|
||||
let fnList = this.saveWaiter.done();
|
||||
|
||||
wx.setStorage<T>({
|
||||
key: this.key,
|
||||
data: this.cache,
|
||||
|
||||
success: (data) => {
|
||||
Logger.log(`数据保存成功! errMsg: ${ data.errMsg }`,
|
||||
LevelLogLabel.InfoLabel, this.StorageLogLabel);
|
||||
},
|
||||
|
||||
fail: (data) => {
|
||||
Logger.log(`数据保存失败! errMsg: ${ data.errMsg }`,
|
||||
LevelLogLabel.FatalLabel, this.StorageLogLabel);
|
||||
},
|
||||
|
||||
complete: () => {
|
||||
fnList();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return new Promise((r) => {
|
||||
|
||||
// 加入等待队列
|
||||
this.saveWaiter.addWaiter(r);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 在缓存中搜索此键值的实例
|
||||
*/
|
||||
private findStorageCache(): boolean {
|
||||
let { storage: storageMap } = getApp<IAppStorageParam>();
|
||||
|
||||
// 查找缓存
|
||||
let storage = storageMap.get(this.key);
|
||||
if (storage) {
|
||||
this.cacheStorage = storage as Storage<T>;
|
||||
return true;
|
||||
};
|
||||
|
||||
// 缓存此实例
|
||||
storageMap.set(this.key, this);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置全部数据
|
||||
*/
|
||||
public async reset() {
|
||||
this.cache = this.defaultData;
|
||||
Logger.logMultiple([LevelLogLabel.InfoLabel, this.StorageLogLabel],
|
||||
`正在重置为默认数据... 数据内容:\n`, this.cache
|
||||
);
|
||||
return this.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultData 键值默认数据
|
||||
*/
|
||||
public constructor(key:string, defaultData?:T) {
|
||||
this.key = key;
|
||||
this.defaultData = defaultData ?? {} as T;
|
||||
this.StorageLogLabel = new LogLabel(
|
||||
`Storage:${ this.key }`, colorRadio(34, 230, 258)
|
||||
);
|
||||
|
||||
// 如果已找到其他实力,将此实例链接到目标实例
|
||||
if (this.findStorageCache()) {
|
||||
|
||||
// 设置默认值
|
||||
for (const key in this.defaultData) {
|
||||
if (this.cache[key] === void 0) {
|
||||
this.set(key, this.defaultData[key]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
// 读取数据到缓存
|
||||
this.cache = wx.getStorageSync<T>(this.key);
|
||||
|
||||
// 使用默认值
|
||||
if(!this.cache) {
|
||||
Logger.log(`找不到 Storage 数据!`,
|
||||
LevelLogLabel.InfoLabel, this.StorageLogLabel);
|
||||
this.reset();
|
||||
} else {
|
||||
Logger.logMultiple([LevelLogLabel.InfoLabel, this.StorageLogLabel],
|
||||
`数据成功从 Storage 读取, 数据内容:\n`, this.cache
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取键值对应数据
|
||||
* @param key 键值
|
||||
*/
|
||||
public get<M extends keyof T>(key:M):T[M] {
|
||||
return this.cache[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置键值对应数据
|
||||
* @param key 键值
|
||||
*/
|
||||
public async set<M extends keyof T>(key:M, value:T[M]):Promise<void> {
|
||||
this.cache[key] = value;
|
||||
return this.save();
|
||||
}
|
||||
}
|
||||
|
||||
export default Storage;
|
||||
export { Storage, StorageState, Waiter, IAppStorageParam, IStorageData };
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#3EA3D8;}
|
||||
</style>
|
||||
<path class="st0" d="M839.8,71.8H715.5c-18.5-34.5-55.1-58.2-96.9-58.2H414.1c-41.9,0-78.3,23.6-96.9,58.2H192.9
|
||||
C131,71.8,80.8,122.2,80.8,184v711.4c0,61.9,50.2,112.1,112.1,112.1h646.9c61.9,0,112.1-50.2,112.1-112.1V184
|
||||
C951.8,122.1,901.6,71.8,839.8,71.8L839.8,71.8z M414.1,72.2h204.5c28.3,0,51.4,23.1,51.4,51.4S646.9,175,618.6,175H414.1
|
||||
c-28.3,0-51.4-23.1-51.4-51.4C362.6,95.3,385.8,72.2,414.1,72.2L414.1,72.2z M893.4,895.4c0,29.6-24,53.6-53.6,53.6H192.9
|
||||
c-29.6,0-53.6-24-53.6-53.6V184c0-29.6,24-53.6,53.6-53.6h111.6c3.5,57.5,51.4,103.1,109.6,103.1h204.5
|
||||
c58.3,0,106.1-45.6,109.6-103.1h111.6c29.6,0,53.6,24,53.6,53.6L893.4,895.4L893.4,895.4z"/>
|
||||
<path class="st0" d="M314.6,730.6H459v-350c0-15.8,9.9-24.4,29.7-25.7c19.8,1.3,30.3,9.9,31.6,25.7v96.9h172
|
||||
c17.1,1.3,26.4,11.2,27.7,29.7c-1.3,19.8-10.6,29.7-27.7,29.7h-172v193.8H722c14.5,1.3,22.4,9.9,23.7,25.7
|
||||
c-1.3,18.4-9.2,28.3-23.7,29.7H314.6c-15.8-1.3-24.4-11.2-25.7-29.7C290.2,740.4,298.8,731.9,314.6,730.6L314.6,730.6z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#3EA3D8;}
|
||||
</style>
|
||||
<path class="st0" d="M838.4,71.7H713.8c-18.5-34.6-55.2-58.3-97.1-58.3H412c-42,0-78.4,23.7-97,58.3H190.4
|
||||
c-62,0-112.2,50.5-112.2,112.3v712.6c0,62,50.3,112.2,112.2,112.2h648c62,0,112.2-50.3,112.2-112.2V184.1
|
||||
C950.6,122.1,900.3,71.7,838.4,71.7z M412,72.1h204.8c28.4,0,51.4,23.1,51.4,51.4c0,28.4-23.1,51.5-51.4,51.5H412
|
||||
c-28.4,0-51.4-23.1-51.4-51.5C360.4,95.2,383.6,72.1,412,72.1z M892,896.6c0,29.6-24.1,53.7-53.7,53.7h-648
|
||||
c-29.6,0-53.7-24.1-53.7-53.7V184.1c0-29.6,24.1-53.7,53.7-53.7h111.8c3.5,57.6,51.4,103.3,109.8,103.3h204.8
|
||||
c58.4,0,106.3-45.7,109.8-103.3h111.8c29.6,0,53.7,24.1,53.7,53.7C892,184.1,892,896.6,892,896.6z"/>
|
||||
<path class="st0" d="M308.4,358h411.9c15.8,1.3,25.1,11.2,27.7,29.7c-1.3,18.5-9.9,27.7-25.7,27.7H528.2V461
|
||||
c52.8,33,103.6,72,152.5,116.8c18.5,19.8,21.8,38.3,9.9,55.4c-13.2,11.9-30.4,8.6-51.5-9.9c-42.3-39.6-79.2-71.3-110.9-95.1V764
|
||||
c-1.3,14.5-11.2,22.4-29.7,23.8c-18.5-1.3-27.7-9.3-27.7-23.8V415.4H310.4c-15.8,0-24.4-9.2-25.7-27.7
|
||||
C284.7,369.2,292.6,359.3,308.4,358z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="D" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#3EA3D8;}
|
||||
</style>
|
||||
<path class="st0" d="M474.1,995.9l5.4,4.9c33.6,27.3,86.1,4,86.1-41.4V729.7h371.2c29.3,0,53-23.7,53-53V346.7l-0.5-7.1
|
||||
c-3.6-26.3-26-45.9-52.5-45.9l-371.2,0.1V64c0-21.7-13.2-41.2-33.4-49.2c-20.2-8-43.2-3-58.1,12.8L49.9,475.3
|
||||
c-19.3,20.4-19.3,52.4,0,72.9L474.1,995.9z M161.4,511.7l298.1-314.7v149.7l0.5,7.2c3.6,26.3,26,45.8,52.5,45.8l371.1,0.1v223.8
|
||||
H512.5l-7.2,0.5c-26.3,3.6-45.8,26-45.8,52.5v149.8L161.4,511.7z M161.4,511.7"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 837 B |
@@ -1 +1 @@
|
||||
<text>pages/Account/Account.wxml</text>
|
||||
<!-- <text>pages/Account/Account.wxml</text> -->
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/* pages/Account/Account.wxss */
|
||||
@@ -1 +0,0 @@
|
||||
/* pages/Information/Information.wxss */
|
||||
@@ -0,0 +1,120 @@
|
||||
@import "../../app.scss";
|
||||
|
||||
$status-bar-left-top-icon-width: 30px;
|
||||
$status-bar-middle-icon-width: 15px;
|
||||
|
||||
view.status-bar {
|
||||
top: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
position: fixed;
|
||||
justify-content: space-between;
|
||||
background-color: #F8F8F8;
|
||||
|
||||
view.select {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
padding-left: 18px;
|
||||
|
||||
image {
|
||||
width: $status-bar-left-top-icon-width;
|
||||
height: $status-bar-left-top-icon-width;
|
||||
filter: $black-filter;
|
||||
}
|
||||
|
||||
view.semester {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
padding-left: 5px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
view.semester-title {
|
||||
@extend %status-bar-title;
|
||||
font-size: .9em;
|
||||
line-height: .9em;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
view.semester-intro {
|
||||
@extend %status-bar-subtitle;
|
||||
font-size: .9em;
|
||||
line-height: .9em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.capsule-holder {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
view.content {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
image {
|
||||
width: $status-bar-middle-icon-width;
|
||||
height: $status-bar-middle-icon-width;
|
||||
filter: $black-filter;
|
||||
}
|
||||
|
||||
view.week {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
height: 100%;
|
||||
|
||||
view.week-title {
|
||||
@extend %status-bar-title;
|
||||
font-weight: 600;
|
||||
font-size: 1.15em;
|
||||
line-height: 1.15em;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
view.week-intro {
|
||||
@extend %status-bar-subtitle;
|
||||
font-size: .85em;
|
||||
line-height: .85em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.status-bar-blank {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
%status-bar-title {
|
||||
color: $theme-color-light-title;
|
||||
}
|
||||
|
||||
%status-bar-subtitle {
|
||||
color: $theme-color-light-text;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark){
|
||||
|
||||
%status-bar-title {
|
||||
color: $theme-color-dark-title;
|
||||
}
|
||||
|
||||
%status-bar-subtitle {
|
||||
color: $theme-color-dark-text;
|
||||
}
|
||||
|
||||
view.status-bar {
|
||||
background-color: #191919;
|
||||
|
||||
view.select image {
|
||||
filter: $white-filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { Modular, Manager, ILifetime } from "../../core/Module";
|
||||
import { Logger, LogLabel, LevelLogLabel, LifeCycleLogLabel, NormalStyle } from "../../core/Logger";
|
||||
|
||||
/**
|
||||
* 在 UI 中显示的数据
|
||||
*/
|
||||
interface IDisplayData {
|
||||
|
||||
/**
|
||||
* 显示内容
|
||||
*/
|
||||
val:string;
|
||||
|
||||
/**
|
||||
* 唯一键值 用来做判断
|
||||
*/
|
||||
key:string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 模组事件
|
||||
*/
|
||||
interface StatusBarEvent {
|
||||
m: IDisplayData
|
||||
};
|
||||
|
||||
/**
|
||||
* 顶部状态栏
|
||||
*/
|
||||
class StatusBar<M extends Manager> extends Modular<M, {}, StatusBarEvent>
|
||||
implements Partial<ILifetime> {
|
||||
|
||||
/**
|
||||
* 导航栏高度补偿
|
||||
*/
|
||||
public static readonly StatusBarHeightExtend:number = 2;
|
||||
|
||||
/**
|
||||
* 页面日志输出标签
|
||||
*/
|
||||
public static readonly StatusBarLabel = new LogLabel(
|
||||
"StatusBar", NormalStyle
|
||||
);
|
||||
|
||||
data = {
|
||||
|
||||
// 导航栏高度
|
||||
barHeight: 65,
|
||||
|
||||
// 状态栏高度
|
||||
barTop: 20,
|
||||
|
||||
// 胶囊占位
|
||||
capsule: 94
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置顶部状态栏高度
|
||||
*/
|
||||
public setHeight() {
|
||||
|
||||
let systemInfo = wx.getSystemInfoSync();
|
||||
let headerPos = wx.getMenuButtonBoundingClientRect();
|
||||
|
||||
//状态栏高度
|
||||
let statusBarHeight = Number(systemInfo.statusBarHeight);
|
||||
|
||||
// 胶囊实际位置,坐标信息不是左上角原点
|
||||
let btnPosI = {
|
||||
|
||||
// 胶囊实际高度
|
||||
height: headerPos.height,
|
||||
width: headerPos.width,
|
||||
|
||||
// 胶囊top - 状态栏高度
|
||||
top: headerPos.top - statusBarHeight,
|
||||
|
||||
// 胶囊bottom - 胶囊height - 状态栏height (胶囊实际bottom 为距离导航栏底部的长度)
|
||||
bottom: headerPos.bottom - headerPos.height - statusBarHeight,
|
||||
|
||||
// 这里不能获取 屏幕宽度,PC端打开小程序会有BUG,要获取窗口高度 - 胶囊right
|
||||
right: systemInfo.windowWidth - headerPos.right
|
||||
}
|
||||
|
||||
// 计算顶部导航栏高度
|
||||
let barHeight = btnPosI.height + btnPosI.top + btnPosI.bottom;
|
||||
|
||||
// 计算胶囊展位
|
||||
let capsule = btnPosI.right + btnPosI.width;
|
||||
|
||||
this.setData({
|
||||
|
||||
// 不知道为什么总是差 4px 距离
|
||||
// 别问为什么 加上就对了
|
||||
barHeight: barHeight + 4 + StatusBar.StatusBarHeightExtend,
|
||||
barTop: statusBarHeight - StatusBar.StatusBarHeightExtend,
|
||||
capsule: capsule
|
||||
});
|
||||
|
||||
Logger.log(`计算并设置 StatusBar 的高度为: ${ barHeight + 4 }px, ` +
|
||||
`状态栏高度: ${ statusBarHeight }px, 胶囊占位: ${ capsule }px`,
|
||||
LevelLogLabel.InfoLabel, StatusBar.StatusBarLabel);
|
||||
|
||||
}
|
||||
|
||||
public onLoad() {
|
||||
|
||||
Logger.log("StatusBar 模块加载...",
|
||||
LevelLogLabel.InfoLabel, LifeCycleLogLabel.OnLoadLabel, StatusBar.StatusBarLabel);
|
||||
|
||||
this.setHeight();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default StatusBar;
|
||||
export { StatusBar };
|
||||
@@ -0,0 +1,72 @@
|
||||
import { Modular, Manager, ILifetime } from "../../core/Module";
|
||||
import { API, IParamSetting } from "../../core/Api";
|
||||
import { Storage } from "../../core/Storage";
|
||||
|
||||
/**
|
||||
* 顶部状态栏
|
||||
*/
|
||||
class TestCore<M extends Manager> extends Modular<M>
|
||||
implements Partial<ILifetime> {
|
||||
|
||||
public override onLoad() {
|
||||
|
||||
let s = new Storage("test", {
|
||||
a: new Date(),
|
||||
be: 2
|
||||
});
|
||||
|
||||
let s2 = new Storage("test", {
|
||||
be: 1,
|
||||
aa: "abc"
|
||||
});
|
||||
|
||||
s2.set("be", 4);
|
||||
|
||||
console.log(s, s2);
|
||||
|
||||
setTimeout(() => {
|
||||
s.set("be", 12);
|
||||
}, 1000)
|
||||
|
||||
interface ITestApiInput {
|
||||
name: string,
|
||||
id: number,
|
||||
info: {
|
||||
data: string
|
||||
}
|
||||
}
|
||||
|
||||
class TestApi extends API<ITestApiInput, {}> {
|
||||
|
||||
public override params: IParamSetting<ITestApiInput> = {
|
||||
name: {
|
||||
tester: "123",
|
||||
isHeader: true
|
||||
},
|
||||
id: {
|
||||
parse: (i) => ++i,
|
||||
},
|
||||
info: {}
|
||||
}
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.initDebugLabel("TestApi");
|
||||
}
|
||||
}
|
||||
|
||||
let api = new TestApi();
|
||||
api.param({
|
||||
name: "123",
|
||||
id: 456,
|
||||
info: {
|
||||
data: "abc"
|
||||
}
|
||||
}).request().wait({
|
||||
success: (d) => console.log(d)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default TestCore;
|
||||
export { TestCore };
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
"usingComponents": {},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@import "./StatusBar.scss"
|
||||
|
||||
|
||||
@@ -1,66 +1,12 @@
|
||||
// pages/Timetable/Timetable.ts
|
||||
Page({
|
||||
import { Manager} from "../../core/Module";
|
||||
import { StatusBar } from "./StatusBar";
|
||||
import { TestCore } from "./TestCore";
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
}
|
||||
/**
|
||||
* 此页面使用 Manager 进行模块化管理
|
||||
* 若要添加先功能请先定义 Modular 并添加至 Manager
|
||||
*/
|
||||
Manager.Page((manager)=>{
|
||||
manager.addModule(StatusBar, "statusBar");
|
||||
manager.addModule(TestCore, "testCore");
|
||||
})
|
||||
@@ -1 +1,30 @@
|
||||
<text>pages/Timetable/Timetable.wxml</text>
|
||||
|
||||
<!-- 顶部状态栏 -->
|
||||
<view class="status-bar" style="height:{{ statusBar$barHeight }}px; padding-top:{{ statusBar$barTop }}px;">
|
||||
|
||||
<!-- 学期选择 -->
|
||||
<view class="select">
|
||||
<image src="/image/ui/last_semester.svg"/>
|
||||
<view class="semester">
|
||||
<view class="semester-title">大四-上</view>
|
||||
<view class="semester-intro">2021-2022</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 周选择 -->
|
||||
<view class="content">
|
||||
<view class="week">
|
||||
<view class="week-title">第1周</view>
|
||||
<view class="week-intro">双击返回本周</view>
|
||||
</view>
|
||||
<image src="/image/ui/selectArror.svg"/>
|
||||
</view>
|
||||
|
||||
<!-- 胶囊占位 -->
|
||||
<view class="capsule-holder" style="width: {{ statusBar$capsule }}px"></view>
|
||||
</view>
|
||||
|
||||
<!-- 状态栏占位 -->
|
||||
<view class="status-bar-blank" style="height: {{ statusBar$barHeight + statusBar$barTop }}px"></view>
|
||||
|
||||
<!-- <text>afdff</text> -->
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"light": {
|
||||
"navigationBarBackgroundColor": "#f6f6f6",
|
||||
"navigationBarBackgroundColor": "#f8f8f8",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#f4f0f1",
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import {LogLabel, LogStyle} from "./Logger";
|
||||
|
||||
// 成功
|
||||
export const SuccessLabel = new LogLabel(
|
||||
"SUCCESS", new LogStyle().setColor("#FFFFFF", "#EE113D").setBorder("5px")
|
||||
);
|
||||
|
||||
// 失败
|
||||
export const FailedLabel = new LogLabel(
|
||||
"SUCCESS", new LogStyle().setColor("#FFFFFF", "#33ff66").setBorder("3px")
|
||||
);
|
||||
|
||||
|
||||
|
||||
// 致命
|
||||
export const FatalLabel = new LogLabel(
|
||||
"FATAL", new LogStyle().setColor("#FFFFFF", "#FF00CC").setBorder("3px")
|
||||
);
|
||||
|
||||
// 错误
|
||||
export const ErrorLabel = new LogLabel(
|
||||
"ERROR", new LogStyle().setColor("#FFFFFF", "#FF0000").setBorder("3px")
|
||||
);
|
||||
|
||||
// 警告
|
||||
export const WarnLabel = new LogLabel(
|
||||
"WARN", new LogStyle().setColor("#FFFFFF", "#FF9900").setBorder("3px")
|
||||
);
|
||||
|
||||
// 消息
|
||||
export const InfoLabel = new LogLabel(
|
||||
"INFO", new LogStyle().setColor("#FFFFFF", "#99FF00").setBorder("3px")
|
||||
);
|
||||
|
||||
// 调试
|
||||
export const DebugLabel = new LogLabel(
|
||||
"DEBUG", new LogStyle().setColor("#FFFFFF", "#00FF99").setBorder("3px")
|
||||
);
|
||||
|
||||
// 追踪
|
||||
export const TraceLabel = new LogLabel(
|
||||
"TRACE", new LogStyle().setColor("#FFFFFF", "#00CCFF").setBorder("3px")
|
||||
);
|
||||
@@ -1,391 +0,0 @@
|
||||
import {LOGGER_CONSOLE, LOGGER_FILTER} from "./Config";
|
||||
|
||||
/**
|
||||
* 调试输出样式
|
||||
*/
|
||||
class LogStyle {
|
||||
|
||||
/**
|
||||
* 日志文字颜色
|
||||
*/
|
||||
private color:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志背景颜色
|
||||
*/
|
||||
private backgroundColor:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字粗细
|
||||
*/
|
||||
private weight:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字大小
|
||||
*/
|
||||
private size:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字字体
|
||||
*/
|
||||
private family:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字圆角
|
||||
*/
|
||||
private borderRadius:string | undefined;
|
||||
|
||||
/**
|
||||
* 日志文字边框
|
||||
*/
|
||||
private border:string | undefined;
|
||||
|
||||
/**
|
||||
* 设置颜色
|
||||
* @param color 日志文字颜色
|
||||
* @param backgroundColor 日志背景颜色
|
||||
*/
|
||||
public setColor(color:string, backgroundColor?:string):LogStyle {
|
||||
this.color = color;
|
||||
this.backgroundColor = backgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置边框
|
||||
* @param borderRadius 日志文字圆角
|
||||
* @param border 日志文字边框
|
||||
*/
|
||||
public setBorder(borderRadius:string, border?:string):LogStyle {
|
||||
this.borderRadius = borderRadius;
|
||||
this.border = border;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文字
|
||||
* @param weight 日志文字粗细
|
||||
* @param family 日志文字字体
|
||||
*/
|
||||
public setFont(weight:string, family:string):LogStyle {
|
||||
this.weight = weight;
|
||||
this.family = family;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文字大小
|
||||
* @param size 日志文字大小
|
||||
*/
|
||||
public setSize(size:string):LogStyle {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符化转义样式
|
||||
*/
|
||||
public stringify():string {
|
||||
let stringArr:string[] = [];
|
||||
|
||||
this.color && stringArr.push(`color:${ this.color }`);
|
||||
this.backgroundColor && stringArr.push(`background-color:${ this.backgroundColor }`);
|
||||
this.weight && stringArr.push(`font-weight:${ this.weight }`);
|
||||
this.family && stringArr.push(`font-family:${ this.family }`);
|
||||
this.borderRadius && stringArr.push(`border-radius:${ this.borderRadius }`);
|
||||
this.border && stringArr.push(`border:${ this.border }`);
|
||||
this.size && stringArr.push(`font-size:${ this.size }`);
|
||||
|
||||
stringArr.push(`margin-bottom:5px`);
|
||||
|
||||
return stringArr.join(";");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志标签
|
||||
*/
|
||||
class LogLabel {
|
||||
|
||||
/**
|
||||
* 关键字
|
||||
* 用于标识这个类别
|
||||
*/
|
||||
public key:string;
|
||||
|
||||
/**
|
||||
* 文字样式
|
||||
*/
|
||||
public style:LogStyle;
|
||||
|
||||
/**
|
||||
* @param key 关键字
|
||||
* @param style 文字样式
|
||||
*/
|
||||
constructor(key:string, style:LogStyle) {
|
||||
this.key = key;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 Logger 输出使用的内容
|
||||
*/
|
||||
public getLoggerOutput():string {
|
||||
return `%c ${ this.key } `;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 Text 输出内容
|
||||
*/
|
||||
public getTextOutput():string {
|
||||
return `[${ this.key }]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 style 格式化
|
||||
*/
|
||||
public getStyleOutput():string {
|
||||
return this.style.stringify();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 栈信息
|
||||
*/
|
||||
class StackInfo {
|
||||
|
||||
/**
|
||||
* 函数名
|
||||
*/
|
||||
public functionName:string | undefined;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
public fileName:string | undefined;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
public url:string | undefined;
|
||||
|
||||
public setInfo(functionName:string, fileName:string, url:string):StackInfo {
|
||||
this.functionName = functionName;
|
||||
this.fileName = fileName;
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取函数调用栈列表
|
||||
*/
|
||||
static getCallStack():StackInfo[] {
|
||||
|
||||
// 获取堆栈信息
|
||||
let stack:string | undefined = new Error().stack;
|
||||
|
||||
if (stack === void 0) return [];
|
||||
|
||||
// 去除 Error
|
||||
stack = stack.replace(/^(Error)\s/, "");
|
||||
|
||||
// 获取堆栈信息
|
||||
let stackList:string[] = stack.split(/\n/);
|
||||
|
||||
let callStack:StackInfo[] = [];
|
||||
|
||||
for(let i = 0; i < stackList.length; i++) {
|
||||
|
||||
let matcher = stackList[i].match(/^\s+at\s+(.+)\s(\(.+\))/);
|
||||
if (matcher === null || matcher.length < 3) continue;
|
||||
|
||||
let fileName = matcher[2].match(/.+\/(.+\..+:\d+:\d+)\)/);
|
||||
if (fileName === null || matcher.length < 2) continue;
|
||||
|
||||
callStack.push(new StackInfo().setInfo(
|
||||
matcher[1], fileName[1], matcher[2]
|
||||
))
|
||||
}
|
||||
|
||||
return callStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 排除的
|
||||
*/
|
||||
static readonly excludeFile:RegExp = /^Logger\.js:\d+:\d+/;
|
||||
|
||||
/**
|
||||
* 获取第一个调用栈
|
||||
*/
|
||||
static getFirstStack():StackInfo | undefined {
|
||||
|
||||
let callStack = this.getCallStack();
|
||||
|
||||
for(let i = 0; i < callStack.length; i++) {
|
||||
|
||||
if(!callStack[i].fileName) continue;
|
||||
|
||||
if(!StackInfo.excludeFile.test(callStack[i].fileName ?? "")) {
|
||||
return callStack[i];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多重内容捆绑
|
||||
* 用于 log 输出
|
||||
*/
|
||||
class MultipleLogContent {
|
||||
|
||||
/**
|
||||
* 输出内容
|
||||
*/
|
||||
private content:any[];
|
||||
|
||||
/**
|
||||
* @param content 输出内容
|
||||
*/
|
||||
public constructor(...content:any[]) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
*/
|
||||
public getContent():any[] {
|
||||
return this.content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日志输出
|
||||
*/
|
||||
class Logger {
|
||||
|
||||
/**
|
||||
* 堆栈路径样式
|
||||
*/
|
||||
static readonly pathStyle:LogStyle = new LogStyle().setColor("#CCCCCC");
|
||||
|
||||
/**
|
||||
* 标签过滤
|
||||
*/
|
||||
static filterLog(filter:Array<RegExp | string>, labels:LogLabel[]):boolean {
|
||||
|
||||
let passNum:number = 0;
|
||||
|
||||
for(let i = 0; i < filter.length; i++) {
|
||||
|
||||
let pass:boolean = false;
|
||||
for(let j = 0; j < labels.length; j++) {
|
||||
|
||||
if(filter[i] instanceof RegExp) {
|
||||
pass = (filter[i] as RegExp).test(labels[j].key)
|
||||
} else {
|
||||
pass = (filter[i] as String) === labels[j].key;
|
||||
}
|
||||
|
||||
if(pass) break;
|
||||
}
|
||||
|
||||
if(pass) passNum ++;
|
||||
}
|
||||
|
||||
return passNum === filter.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否应该输出
|
||||
* @param labels 使用标签
|
||||
*/
|
||||
static testLog(...labels:LogLabel[]):boolean {
|
||||
|
||||
if(!LOGGER_CONSOLE) return false;
|
||||
|
||||
let isLogging = false;
|
||||
for(let i = 0; i < LOGGER_FILTER.length; i++) {
|
||||
|
||||
// 判断是否进行输出
|
||||
isLogging = Logger.filterLog(LOGGER_FILTER[i], labels);
|
||||
|
||||
if(isLogging) break;
|
||||
}
|
||||
|
||||
return isLogging;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param styledLabel calcStyle的处理结果
|
||||
*/
|
||||
static addFileNameLabel():LogLabel {
|
||||
|
||||
// 获得调用堆栈
|
||||
let stack = StackInfo.getFirstStack();
|
||||
|
||||
return new LogLabel(stack?.fileName ?? "", Logger.pathStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集计算样式
|
||||
* @param labels 使用标签
|
||||
*/
|
||||
static calcStyle(...labels:LogLabel[]):[string[], string[]] {
|
||||
|
||||
let consoleLabels:string[] = [];
|
||||
let consoleStyles:string[] = [];
|
||||
|
||||
// 放置标签
|
||||
for(let i = 0; i < labels.length; i++) {
|
||||
consoleLabels.push(labels[i].getLoggerOutput());
|
||||
|
||||
if (i !== ( labels.length - 1))
|
||||
consoleLabels.push("%c ");
|
||||
|
||||
consoleStyles.push(labels[i].getStyleOutput());
|
||||
|
||||
if (i !== ( labels.length - 1))
|
||||
consoleStyles.push("");
|
||||
}
|
||||
|
||||
return [consoleLabels, consoleStyles];
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试输出
|
||||
* @param content 输出内容
|
||||
* @param label 使用标签
|
||||
*/
|
||||
static log<T>(content:T, ...labels:LogLabel[]):T {
|
||||
|
||||
let fileNameLabel = Logger.addFileNameLabel();
|
||||
|
||||
if(!Logger.testLog(...labels, fileNameLabel)) return content;
|
||||
|
||||
let styledLabel = Logger.calcStyle(...labels);
|
||||
|
||||
console.log(
|
||||
styledLabel[0].join("") + fileNameLabel.getLoggerOutput(),
|
||||
...[...styledLabel[1], fileNameLabel.getStyleOutput()],
|
||||
content
|
||||
);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多重调试输出
|
||||
* @param labels 输出内容
|
||||
* @param content 使用标签
|
||||
*/
|
||||
static logM<T>(labels:LogLabel[], ...content:T[]):T[] {
|
||||
return Logger.log<T[]>(content, ...labels);
|
||||
}
|
||||
}
|
||||
|
||||
export default Logger;
|
||||
export {Logger, LogStyle, LogLabel}
|
||||
+5
-2
@@ -5,7 +5,7 @@
|
||||
},
|
||||
"miniprogramRoot": "miniprogram/",
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "2.21.0",
|
||||
"libVersion": "2.16.1",
|
||||
"projectname": "mini-dlpu-v3",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
@@ -35,7 +35,7 @@
|
||||
"outputPath": ""
|
||||
},
|
||||
"enableEngineNative": false,
|
||||
"useIsolateContext": true,
|
||||
"useIsolateContext": false,
|
||||
"userConfirmedBundleSwitch": false,
|
||||
"packNpmManually": false,
|
||||
"packNpmRelationList": [],
|
||||
@@ -51,5 +51,8 @@
|
||||
"simulatorType": "wechat",
|
||||
"simulatorPluginLibVersion": {},
|
||||
"appid": "wx7d809f5e8955843d",
|
||||
"scripts": {
|
||||
"beforeCompile": ""
|
||||
},
|
||||
"condition": {}
|
||||
}
|
||||
+5
-1
@@ -19,7 +19,11 @@
|
||||
"lib": ["ES2020"],
|
||||
"typeRoots": [
|
||||
"./typings"
|
||||
]
|
||||
],
|
||||
"baseUrl": "./miniprogram/",
|
||||
"paths": {
|
||||
"@logger": ["logger/"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
|
||||
Reference in New Issue
Block a user