Skip to content

Instantly share code, notes, and snippets.

View Houserqu's full-sized avatar
🏠
Working from home

Houser Houserqu

🏠
Working from home
View GitHub Profile
@Houserqu
Houserqu / index.html
Last active May 5, 2021 01:34
html 常用 meta
<!-- 禁止缩放 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>
/**
len: 长度
radix:
*/
export default function (len, radix) {
let CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
let chars = CHARS, uuid = [], i;
radix = radix || chars.length;
if (len) {
export default function () {
  let ua = {}, agent = navigator.userAgent, m;
  ua.iPod = agent.indexOf("iPod") > -1;
  ua.iPad = agent.indexOf("iPad") > -1;
  ua.iPhone = agent.indexOf("iPhone") > -1;
  agent.indexOf("Android") > -1 && (ua.android = parseFloat(agent.slice(agent.indexOf("Android") + 8)));

  if (ua.iPad || ua.iPhone || ua.iPod) {
    m = /OS (\d+)_/.exec(agent);
@Houserqu
Houserqu / query.md
Created May 5, 2021 01:37
query-string

URL 的操作,也可以使用第三库 querystring

根据 key 获取 query 的值

export default function (name, url) {
  let src = url || window.location.href;
  if (name && src) {
    var r = new RegExp("(\\?|#|&|^)" + name + "=([^&^#]*)(#|&|$)");
    var m = src.match(r);
@Houserqu
Houserqu / index.md
Last active May 5, 2021 01:38
material-ui

material-ui 组件库的消息通知组件的封装,可以在任何地方调用 参考

思路:snackbar 以组件的形式注册后,子自己通过props调用,这里暴露出组件的 ref 从而使用 props 触发

import { useSnackbar, VariantType, WithSnackbarProps } from 'notistack'
import React from 'react'

interface IProps {
// 处理 ios 上输入完页面没有恢复到底部到问题
function fixIOSInput() {
setTimeout(function () {
var tagName = document.activeElement.tagName.toLowerCase()
if (tagName !== 'input' || tagName !== 'textarea') {
window.document.documentElement.scrollTop = window.document.body.scrollHeight;
}
}, 0)
}
@Houserqu
Houserqu / textarea.md
Created May 5, 2021 01:51
textarea自适应

实现原理:textarea本身并不会随着文本高度而增高。给textarea套上外容器,使用绝对定位,设置height:100%; width:100%; 这样textarea就可以随着外容器的高度变化而变化。再利用块级元素填充文字,块元素可以随着文本高度自动增高。设置块元素visibility: hidden;样式与textarea一致即可。 https://juejin.im/post/6844903682266529805

<Container>
  <div className='text'>
	  <div className='hidden'>{decodeText}</div>
	  <Input
	    className='textarea'
 disabled
@Houserqu
Houserqu / index.md
Created May 5, 2021 01:51
装饰器路由实现

使用装饰器和映射,可以优雅的给 Controller 中的方法绑定路由

方法装饰器

用于定义路由路径和请求类型

import 'reflect-metadata'

type Method = 'get' | 'post' |'put'
@Houserqu
Houserqu / index.md
Last active May 5, 2021 01:54
typeorm

Repository 联查不支持 where,限制很多,使用 querybuild 和 leftJoinAndMapOne 方法可以将管理表作为一个属性

@Entity("record", { schema: "demo" })
export class Record {
  ...

  question: Question // 定义管理表挂载的属性
}