Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

214 linhas
6.0 KiB

  1. // import {toast} from "react-toastify";
  2. import DialogTitle from "@mui/material/DialogTitle";
  3. import DialogContent from "@mui/material/DialogContent";
  4. import DialogContentText from "@mui/material/DialogContentText";
  5. import DialogActions from "@mui/material/DialogActions";
  6. import {Button} from "@mui/material";
  7. import Dialog from "@mui/material/Dialog";
  8. import * as React from "react";
  9. import { toast } from "react-toastify";
  10. export function getDeletedRecordWithRefList(referenceList, updatedList){
  11. return referenceList.filter(x => !updatedList.includes(x)) ;
  12. }
  13. export function getIdList(input){
  14. const output = input.map(function (obj) {
  15. return obj.id;
  16. });
  17. return output;
  18. }
  19. export function getObjectById(list, id){
  20. const obj = list.find((element) => {
  21. return element.id === id;
  22. });
  23. return obj === undefined || Object.keys(obj).length <= 0? null : obj
  24. }
  25. export function removeObjectWithId(arr, id) {
  26. const arrCopy = Array.from(arr);
  27. const objWithIdIndex = arrCopy.findIndex((obj) => obj.id === id);
  28. arrCopy.splice(objWithIdIndex, 1);
  29. return arrCopy;
  30. }
  31. export function getDateString(queryDateArray) {
  32. return(
  33. queryDateArray[0]
  34. + "-" +
  35. queryDateArray[1]
  36. + "-" +
  37. queryDateArray[2]
  38. + " " +
  39. queryDateArray[3]
  40. + ":" +
  41. queryDateArray[4]
  42. + ":" +
  43. queryDateArray[5]
  44. )
  45. }
  46. export const notifySaveSuccess = () => {
  47. const userType = JSON.parse(localStorage.getItem("userData")).type
  48. toast.success(userType === "GLD" ? 'Save success!' : "儲存成功!", {
  49. position: "bottom-right",
  50. autoClose: 5000,
  51. hideProgressBar: false,
  52. closeOnClick: true,
  53. pauseOnHover: true,
  54. draggable: true,
  55. progress: undefined,
  56. theme: "light",
  57. })};
  58. export const notifyCreateSuccess = () => {
  59. const userType = JSON.parse(localStorage.getItem("userData")).type
  60. toast.success(userType === "GLD" ? 'Create success!' : "創建成功!", {
  61. position: "bottom-right",
  62. autoClose: 5000,
  63. hideProgressBar: false,
  64. closeOnClick: true,
  65. pauseOnHover: true,
  66. draggable: true,
  67. progress: undefined,
  68. theme: "light",
  69. })};
  70. export const notifyVerifySuccess = () => {
  71. const userType = JSON.parse(localStorage.getItem("userData")).type
  72. toast.success(userType === "GLD" ? 'Verify success!' : "驗證成功!", {
  73. position: "bottom-right",
  74. autoClose: 5000,
  75. hideProgressBar: false,
  76. closeOnClick: true,
  77. pauseOnHover: true,
  78. draggable: true,
  79. progress: undefined,
  80. theme: "light",
  81. })};
  82. export const notifyDeleteSuccess = () => {
  83. const userType = JSON.parse(localStorage.getItem("userData")).type
  84. toast.success(userType === "GLD" ? 'Delete success!' : "刪除成功!", {
  85. position: "bottom-right",
  86. autoClose: 5000,
  87. hideProgressBar: false,
  88. closeOnClick: true,
  89. pauseOnHover: true,
  90. draggable: true,
  91. progress: undefined,
  92. theme: "light",
  93. })};
  94. export const notifyLockSuccess = () => {
  95. toast.success('Lock success!', {
  96. position: "bottom-right",
  97. autoClose: 5000,
  98. hideProgressBar: false,
  99. closeOnClick: true,
  100. pauseOnHover: true,
  101. draggable: true,
  102. progress: undefined,
  103. theme: "light",
  104. })};
  105. export const notifyUnlockSuccess = () => {
  106. toast.success('Unlock success!', {
  107. position: "bottom-right",
  108. autoClose: 5000,
  109. hideProgressBar: false,
  110. closeOnClick: true,
  111. pauseOnHover: true,
  112. draggable: true,
  113. progress: undefined,
  114. theme: "light",
  115. })};
  116. export const notifyActiveSuccess = () => {
  117. toast.success('Active success!', {
  118. position: "bottom-right",
  119. autoClose: 5000,
  120. hideProgressBar: false,
  121. closeOnClick: true,
  122. pauseOnHover: true,
  123. draggable: true,
  124. progress: undefined,
  125. theme: "light",
  126. })};
  127. export const notifyDownloadSuccess = () => {
  128. const userType = JSON.parse(localStorage.getItem("userData")).type
  129. toast.success(userType === "GLD" ? 'Download success!' : "下載成功!", {
  130. position: "bottom-right",
  131. autoClose: 5000,
  132. hideProgressBar: false,
  133. closeOnClick: true,
  134. pauseOnHover: true,
  135. draggable: true,
  136. progress: undefined,
  137. theme: "light",
  138. })};
  139. export const notifyActionSuccess = (actionMsg) => {
  140. toast.success(`${actionMsg}`, {
  141. position: "bottom-right",
  142. autoClose: 5000,
  143. hideProgressBar: false,
  144. closeOnClick: true,
  145. pauseOnHover: true,
  146. draggable: true,
  147. progress: undefined,
  148. theme: "light",
  149. })};
  150. export const notifyActionError = (actionMsg) => {
  151. toast.error(`${actionMsg}`, {
  152. position: "bottom-right",
  153. autoClose: 5000,
  154. hideProgressBar: false,
  155. closeOnClick: true,
  156. pauseOnHover: true,
  157. draggable: true,
  158. progress: undefined,
  159. theme: "light",
  160. })};
  161. export function prettyJson(json){
  162. console.log(json);
  163. console.log(JSON.stringify(json, null, 2));
  164. return (
  165. <div>{JSON.stringify(json, null, 2)}</div>
  166. );
  167. }
  168. export function GeneralConfirmWindow({
  169. isWindowOpen,
  170. title,
  171. content,
  172. onNormalClose,
  173. onConfirmClose}){
  174. return (
  175. <Dialog
  176. open={isWindowOpen}
  177. onClose={onNormalClose}
  178. aria-labelledby="alert-dialog-title"
  179. aria-describedby="alert-dialog-description"
  180. >
  181. <DialogTitle id="alert-dialog-title">
  182. {title}
  183. </DialogTitle>
  184. <DialogContent>
  185. <DialogContentText id="alert-dialog-description">
  186. {content}
  187. </DialogContentText>
  188. </DialogContent>
  189. <DialogActions>
  190. <Button onClick={onNormalClose}>Cancel</Button>
  191. <Button onClick={onConfirmClose} autoFocus>
  192. Confirm
  193. </Button>
  194. </DialogActions>
  195. </Dialog>
  196. )
  197. }