国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

響應式網(wǎng)站建站seo初學教程

響應式網(wǎng)站建站,seo初學教程,長沙做網(wǎng)站建設的,什么樣的網(wǎng)站可以做站內(nèi)站注意:以下代碼使用 typeScript 開發(fā),如果想在 js 中使用,可參考 npm 已經(jīng)發(fā)布的包:https://www.npmjs.com/package/uni-easy-file NPM 使用 如果想直接在 npm 項目中使用可以直接執(zhí)行以下命令 npm i uni-easy-file然后直接使用 …

注意:以下代碼使用 typeScript 開發(fā),如果想在 js 中使用,可參考 npm 已經(jīng)發(fā)布的包:https://www.npmjs.com/package/uni-easy-file

NPM 使用

如果想直接在 npm 項目中使用可以直接執(zhí)行以下命令

npm i uni-easy-file

然后直接使用

import {EasyFile} from 'uni-easy-file';EasyFile.mainName("filePath");

項目源碼

參考 github 地址:https://github.com/jl15988/uni-easy-file

主要源碼

FileTypes 文件

/*** 文件類型*/
class FileTypes {imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];documentTypes = ['pdf', 'doc', 'docx', 'xls', 'xlsx'];videoTypes = ['mp4', 'avi', 'mov', 'rmvb', 'flv', '3gp', 'wmv', 'mkv', 'ts', 'webm', 'm4v'];audioTypes = ['mp3', 'wav', 'wma', 'ogg', 'aac', 'flac', 'ape', 'm4a'];compressTypes = ['zip', 'rar', '7z', 'tar', 'gz', 'bz2'];codeTypes = ['html', 'css', 'js', 'json', 'xml', 'yaml', 'yml', 'sql', 'java', 'py', 'php', 'sh', 'bat', 'cmd', 'ps1', 'go', 'ts', 'vue', 'jsx', 'tsx', 'less', 'scss', 'sass', 'styl', 'coffee', 'md', 'markdown', 'txt'];excelTypes = ['xls', 'xlsx'];wordTypes = ['doc', 'docx'];pptTypes = ['ppt', 'pptx'];pdfTypes = ['pdf'];textTypes = ['txt'];markdownTypes = ['md', 'markdown'];
}export default new FileTypes()

EasyFile 文件

import FileTypes from "./FileTypes";/*** 文件工具*/
class EasyFile {types = FileTypes;setTypes(types: any) {// @ts-ignorethis.types = types;}/*** 獲取文件名(包括擴展名)** ```* http://www.example.com/a/b/c.jpg => c.jpg* ```* @param {string} url 文件地址* @return {string}*/fileName(url: string): string {if (!url) return '';return url.split('/').pop()!;}/*** 獲取文件擴展名** ```* http://www.example/com/a/b/c.jpg => jpg* ```* @param {string} url 文件地址* @return {string}*/extName(url: string): string {if (!url) return '';return this.fileName(url).split('.').pop()!;}/*** 獲取文件主名(不包括擴展名)** ```* http://www.example.com/a/b/c.jpg => c* ```* @param {string} url 文件地址* @return {string}*/mainName(url: string): string {if (!url) return '';return this.fileName(url).split('.').shift()!;}/*** 獲取文件路徑** ```* http://www.example.com/a/b/c.jpg => http://www.example.com/a/b* ```* @param {string} url 文件地址* @return {string}*/pathName(url: string): string {if (!url) return '';return url.split('/').slice(0, -1).join('/');}/*** 判斷是否是指定類型* @param {string} url 文件地址* @param {string[]} types 類型數(shù)組* @return {boolean}*/isType(url: string, types: string[]): boolean {const extName = this.extName(url).toLowerCase();return types.includes(extName);}/*** 判斷是否是圖片* @param {string} url 文件地址* @return {boolean}*/isImage(url: string): boolean {return this.isType(url, this.types.imageTypes);}/*** 判斷是否是文檔* @param {string} url 文件地址* @return {boolean}*/isDocument(url: string): boolean {return this.isType(url, this.types.documentTypes);}/*** 判斷是否是視頻* @param {string} url 文件地址* @return {boolean}*/isVideo(url: string): boolean {return this.isType(url, this.types.videoTypes);}/*** 判斷是否是音頻* @param {string} url 文件地址* @return {boolean}*/isAudio(url: string): boolean {return this.isType(url, this.types.audioTypes);}/*** 判斷是否是壓縮文件* @param {string} url 文件地址* @return {boolean}*/isCompress(url: string): boolean {return this.isType(url, this.types.compressTypes);}/*** 判斷是否是代碼文件* @param {string} url 文件地址* @return {boolean}*/isCode(url: string): boolean {return this.isType(url, this.types.codeTypes);}/*** 判斷是否是Excel文件* @param {string} url 文件地址* @return {boolean}*/isExcel(url: string): boolean {return this.isType(url, this.types.excelTypes);}/*** 判斷是否是Word文件* @param {string} url 文件地址* @return {boolean}*/isWord(url: string): boolean {return this.isType(url, this.types.wordTypes);}/*** 判斷是否是PPT文件* @param {string} url 文件地址* @return {boolean}*/isPpt(url: string): boolean {return this.isType(url, this.types.pptTypes);}/*** 判斷是否是PDF文件* @param {string} url 文件地址* @return {boolean}*/isPdf(url: string): boolean {return this.isType(url, this.types.pdfTypes);}/*** 判斷是否是文本文件* @param {string} url 文件地址* @return {boolean}*/isText(url: string): boolean {return this.isType(url, this.types.textTypes);}/*** 判斷是否是Markdown文件* @param {string} url 文件地址* @return {boolean}*/isMarkdown(url: string): boolean {return this.isType(url, this.types.markdownTypes);}/*** 判斷是否是Office文件* @param {string} url 文件地址* @return {boolean}*/isOffice(url: string): boolean {return this.isWord(url) || this.isExcel(url) || this.isPpt(url);}/*** 判斷是否是Office或PDF文件* @param {string} url 文件地址* @return {boolean}*/isOfficeOrPdf(url: string): boolean {return this.isOffice(url) || this.isPdf(url);}/*** 獲取文件臨時地址* @param {string} url 文件地址* @return {Promise<string>}*/getFileTempPath(url: string): Promise<string> {return new Promise((resolve, reject) => {if (!url) {reject('文件地址為空');return;}uni.downloadFile({url,success: (res) => {resolve(res.tempFilePath);},fail: (e) => {reject(e);},});});}/*** 打開文件** 根據(jù)文件類型調(diào)用不同的api打開文件* - 圖片類文件調(diào)用預覽圖片(uni.previewImage)* - office及pdf類型文件調(diào)用打開文檔(uni.openDocument)* - 其他類型不支持* @param {string} url 文件地址* @return {Promise<unknown>}*/async openFile(url: string): Promise<unknown> {return new Promise(async (resolve, reject) => {if (!url) {reject('文件地址為空');return;}let tempPath = '';try {tempPath = await this.getFileTempPath(url);} catch (e) {reject(e);return;}this.openFileByTempPath(tempPath).then(res => {resolve(res);}).catch(e => {reject(e);})});}/*** 根據(jù)臨時地址打開文件** 根據(jù)文件類型調(diào)用不同的api打開文件* - 圖片類文件調(diào)用預覽圖片(uni.previewImage)* - office及pdf類型文件調(diào)用打開文檔(uni.openDocument)* - 其他類型不支持* @param {string} tempPath 文件臨時地址* @return {Promise<unknown>}*/async openFileByTempPath(tempPath: string): Promise<unknown> {return new Promise(async (resolve, reject) => {if (!tempPath) {reject('文件地址為空');return;}if (this.isImage(tempPath)) {// 調(diào)用微信api預覽圖片uni.previewImage({// 開啟時右上角會有三點,點擊可以保存showMenu: true,urls: [tempPath],current: tempPath,success: (res) => {resolve(res);},fail: (res) => {reject(res);}});} else if (this.isOfficeOrPdf(tempPath)) {uni.openDocument({filePath: tempPath,// 開啟時右上角會有三點,點擊可以保存showMenu: true,success: (res) => {resolve(res);},fail: (res) => {reject(res);}});}});}/*** 獲取文件 MD5** 僅獲取文件 MD5 時建議使用此方法,如果同時獲取文件大小,建議直接使用 `getFileInfo` 方法** | App | H5 | 微信小程序 |* | --- | --- | --- |* | √ | √ | × |** @param {string} url 文件地址* @return {Promise<string|undefined>}*/md5(url: string): Promise<string | undefined> {return new Promise(async (resolve, reject) => {let tempPath = '';try {tempPath = await this.getFileTempPath(url);} catch (e) {reject(e);return;}uni.getFileInfo({filePath: tempPath,digestAlgorithm: 'md5',success: (res) => {resolve(res.digest);},fail: (e) => {reject(e);},});});}/*** 獲取文件 SHA1** 僅獲取文件 SHA1 時建議使用此方法,如果同時獲取文件大小,建議直接使用 `getFileInfo` 方法** | App | H5 | 微信小程序 |* | --- | --- | --- |* | √ | √ | × |** @param {string} url 文件地址* @return {Promise<string|undefined>}*/sha1(url: string): Promise<string | undefined> {return new Promise(async (resolve, reject) => {let tempPath = '';try {tempPath = await this.getFileTempPath(url);} catch (e) {reject(e);return;}uni.getFileInfo({filePath: tempPath,digestAlgorithm: 'sha1',success: (res) => {resolve(res.digest);},fail: (e) => {reject(e);},});});}/*** 獲取文件大小,以字節(jié)為單位** 僅獲取文件大小時建議使用此方法,如果同時獲取文件摘要,建議直接使用 `getFileInfo` 方法** | App | H5 | 微信小程序 |* | --- | --- | --- |* | √ | √ | × |** @param {string} url 文件地址* @return {Promise<number>}*/size(url: string): Promise<number> {return new Promise(async (resolve, reject) => {let tempPath = '';try {tempPath = await this.getFileTempPath(url);} catch (e) {reject(e);return;}uni.getFileInfo({filePath: tempPath,success: (res) => {resolve(res.size);},fail: (e) => {reject(e);},});});}/*** 獲取文件信息** | App | H5 | 微信小程序 |* | --- | --- | --- |* | √ | √ | × |** @param {string} url 文件地址* @param {'md5'|'sha1'} digestAlgorithm 摘要算法,支持 md5、sha1* @return {Promise<UniApp.GetFileInfoSuccess>}*/getFileInfo(url: string, digestAlgorithm: 'md5' | 'sha1' = 'md5'): Promise<UniApp.GetFileInfoSuccess> {return new Promise(async (resolve, reject) => {let tempPath = '';try {tempPath = await this.getFileTempPath(url);} catch (e) {reject(e);return;}uni.getFileInfo({filePath: tempPath,digestAlgorithm: digestAlgorithm,success: (res) => {resolve(res);},fail: (e) => {reject(e);},});});}
}export default new EasyFile();
http://m.aloenet.com.cn/news/40847.html

相關文章:

  • 煙臺微信網(wǎng)站建設網(wǎng)站搜索優(yōu)化
  • 懷化市建設局門戶網(wǎng)站網(wǎng)絡營銷推廣平臺
  • 定制型網(wǎng)站開發(fā)2345網(wǎng)址導航智能主板
  • 商丘哪里做網(wǎng)站百度收錄提交入口網(wǎng)址
  • dede網(wǎng)站打開速度慢如何優(yōu)化seo關鍵詞
  • 百度如何搜索到自己的網(wǎng)站網(wǎng)站綜合查詢工具
  • 鄭州電商網(wǎng)站開發(fā)港港網(wǎng)app下載最新版
  • angular2是做網(wǎng)站的還是手機的seo排名的公司
  • app運營流程上海外貿(mào)seo公司
  • 樂清網(wǎng)站建設網(wǎng)站建設網(wǎng)站的宣傳與推廣
  • 旅游景區(qū)網(wǎng)站源碼個人網(wǎng)站設計成品
  • 建c2c網(wǎng)站費用拉新推廣賺錢的app
  • 浙江網(wǎng)站建設企業(yè)軟文類型
  • 免費做的網(wǎng)站怎么設置域名京津冀協(xié)同發(fā)展
  • 營銷加盟網(wǎng)站建設網(wǎng)站維護是什么意思
  • erp定制開發(fā)價格澳門seo關鍵詞排名
  • 做網(wǎng)站阿里云買哪個服務器好點汽車推廣軟文
  • 長沙制作網(wǎng)頁網(wǎng)站杭州網(wǎng)絡
  • 一品威客網(wǎng)怎么樣seo免費優(yōu)化網(wǎng)站
  • win7iis配置網(wǎng)站百度搜索引擎網(wǎng)址
  • 整站優(yōu)化網(wǎng)站報價公司網(wǎng)站建設全包
  • 網(wǎng)站開發(fā)團隊取什么名字好怎么引流怎么推廣自己的產(chǎn)品
  • 長春怎么做網(wǎng)站建站流程新手搭建網(wǎng)站第一步
  • 商城網(wǎng)站開發(fā)教程視頻北京網(wǎng)絡營銷推廣
  • 歐美設計網(wǎng)站推薦app拉新平臺哪個好傭金高
  • 密云做網(wǎng)站的產(chǎn)品關鍵詞大全
  • 建站行業(yè)的利潤百度指數(shù)里的資訊指數(shù)是什么
  • 不銹鋼公司網(wǎng)站源碼 網(wǎng)站建設 產(chǎn)品3級分類asp源碼域名查詢注冊商
  • 360度全景街景地圖陽江seo
  • 北京營銷型網(wǎng)站建設培訓百度怎么優(yōu)化網(wǎng)站關鍵詞